Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rename remote branch on bitbucket

Is it possible to rename a remote branch on Bitbucket?

I found a command to do it locally git branch -m old-name new-name.

But not sure if this is the correct way and what will happen when I push it.

like image 622
pensee Avatar asked Oct 28 '25 01:10

pensee


1 Answers

I'd like to update these answers a bit.

  1. First rename the branch.
# if on the branch
git branch -m new-branch-name

# if on a different branch
git branch -m old-branch-name new-branch-name
  1. Update the remote, in this case Bitbucket.
# Delete the old branch on remote
git push origin --delete old-branch-name

# Push the new branch to remote
git push origin new-branch-name

# Reset the upstream branch
git push origin -u new-branch-name
  1. Optionally, let your team know to update their local repositories.
git fetch --all
git checkout new-branch-name

This worked well for me.

like image 146
Brent Martin Miller Avatar answered Oct 30 '25 16:10

Brent Martin Miller