Creating branch from an old commit

avivpr May 14, 2018

Hello, how can i create a branch from an old commit?

 

thanks

1 answer

1 accepted

Kristy
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 17, 2018

Unfortunately there is no way in the UI to create a branch from an old commit.

You can create a branch from a commit in git using your terminal and the command:

git branch <branchname> <commitHash>
Julius Davies _bit-booster_com_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 18, 2018

 

There is a way.  It's a little awkward, but it works.

1.  Click on the commit in the web UI.

2.  Click on the "[+]" button next to the word "No Tags" (far right middle of screen).  (Or if the commit already has a tag, just use that to create the branch.)

3.  Create a temporary tag against the commit.  Click the "Create Tag" button to save your tag.

4.  Go to the "Create Branch" dialog.  Find your tag.  Use that!

5.  Go back to the commit from step 1. and delete the tag you created.

 

By cosmic coincidence, this works on both Bitbucket Cloud (bitbucket.org) AND Bitbucket Server!  Despite these two Bitbucket implementations being very different, the UI for doing this is pretty much the same in both.

- Sylvie @ Bit-Booster

(We maintain 3 add-ons for Bitbucket Server:  Rebase Squash Amend, Git Graph for JIRA, and Control Freak).

Like # people like this
Kristy
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 20, 2018

I actually hadn't considered doing that. It's certainly not our recommended way of creating a branch from a commit, but you're right - it works!

If someone wants to create branches often then they are probably going to have a clone handy - in which case it would be easier to just do it locally and push the ref. But if this is a one-off, and the person creating the branch doesn't have a local clone, then perhaps doing it in this round-about way would be quicker!

jaromor April 16, 2019

Hello Kristy

Even when you have a local clone, some repositories will let you only push commits that are signed by you. (I.e. you won't be allowed to push commits stored in your local clone that are signed by your colleague.)

Cheers

  Jarda

chris October 4, 2022

I can follow steps 1-4, but how do I perform step 5 "Go back to the commit from step 1. and delete the tag you created"?  A Bitbucket Cloud commit lists all the tags associated with the commit, but AFAICT it doesn't provide an option to delete a tag.

Either I must leave the temporary tag or use the terminal to delete the tag.  And if using the terminal, I might as well use it to directly create the tag.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events