Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Is there a way to rename a branch?

Rolf Marsh March 15, 2018

I apparently have some branches out of sync; is there a way to rename a branch?

7 answers

17 votes
Mikael Sandberg
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 15, 2018

You would need to do the renaming locally in your repository. But before you do that, delete the branch in Bitbucket, do a fetch in your local clone to update it (if doing it from Sourcetree, make sure you check prune tracking branches, from cmd use git fetch -p). Then you can rename the branch and push it back to Bitbucket.

14 votes
Gerhard Pretorius June 4, 2019

This might be helpful too.

From: https://www.w3docs.com

Richie Edwards
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 11, 2022

Thanks! Worked perfectly.

Like Admir Husić likes this
Alexis Evans February 10, 2023

Very helpful article, thanks for the link!

vivek.yadav
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 15, 2024

It was really helpful. Thank you so much for posting this.

Like Richie Edwards likes this
8 votes
Tim Razik March 23, 2020

Officially I don't see a way to rename them, but we have had to do that in some cases.  What we do is basically the following

We have branch bugfix/JIRA-1  and want to rename it to bugfix/JIRA-100
All I usually do is take bugfix/JIRA-1 and create a branch off of that called bugfix/JIRA-100
At that point 1 and 100 should be identical.
I can then delete bugfix/JIRA-1.

You could do this via the bitbucket UI or command line as GErhard_Pretorius linked above.  I personally like the UI in this case as it saves me the step of having to push to origin.

Muideen Ololade Adeleke
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
February 19, 2024

of the smartest move i have seen lol. nice

4 votes
Rick Fleischer
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 6, 2020

To summarize the other answers: No, there is no way to rename.  You can copy and delete, to achieve a similar effect.  But if there is, say, a pull request in progress, you can't avoid losing the comments and approvals.

Paul Mansfield March 3, 2021

this seems to me to be an annoying missing feature of bitbucket!

Like # people like this
1 vote
Arif Z June 29, 2021

So to summarise:

- git pull (locally cloned, to get latest changes)

- delete remote branch on BitBucket

- git fetch -p

- git branch -m <branch_name>

- git push -u <remote> <branch_name> (push to remote)

 

or

 

- create new branch from the branch in BitBucket

- delete the prev branch

0 votes
Godspower Ogaga Uti
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 8, 2021

while on the current branch: git branch -m "local_branch_name"

0 votes
Sudarshan Dhakal
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 1, 2020

if you are doing it from visual studio, in team explorer, right click the branch and rename, one issue i had was renaming the branch to lower case (Dev -> dev), in that case i just renamed to dev1 and then to dev. Hope this helps.

Tim Razik March 3, 2021

Linux and Windows work differently with case sensitivity.  While on linux you can have branch1 and Branch1, that will cause a conflict on windows.  If you are a cross platform shop, you can configure bitbucket to ignore case on branch names. 

 

https://confluence.atlassian.com/bitbucketserverkb/case-sensitivity-in-branch-name-causes-issue-816521190.html

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events