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

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Why does Bitbucket not delete the branch when closing it?

Deleted user Mar 29, 2016

When you create a pull request in Bitbucket you can select the option to "Close Branch" or if you did not select that option when it was created when it is merged you can chose to "Close" it at that time too. 

However, by selecting to close the branch does absolutely nothing to the branch in any interface except for Bitbucket.  So I am not going to ask Atlassian why they do not delete the branch.  What I want to know is, what is the benefitto me the end user/customer, does this purposeful design option provide?  Because all I can see is that, it just clutters up the branch lists in SourceTree and cause me to do additional "work" that, frankly, I do not understand why I should be doing it anyway.

Because Bitbucket does not delete the branch, what is the suggested method for deleting these branches and how long should they be kept?  I assume that you have a automated process for "cleaning" up these after the assigned duration that they should be kept.  So if you would please provide a link to that documentation, that would be great!     

5 answers

I have confirmed that this issue still exist:

  1. checkout branch
  2. push to origin & create pull request (check 'close this branch')
  3. merge PR with close this branch check.
  4. delete local branch

The merged branch is not listed in the web interface but it can still be checked out locally. It will also show in the remote list if i run

git branch -r

manual fix:

git remote prune origin

useful link
https://stackoverflow.com/questions/20106712/what-are-the-differences-between-git-remote-prune-git-prune-git-fetch-prune/22701488

1 vote
Felix Atlassian Team Mar 29, 2016

Hi @Dale Cook,

However, by selecting to close the branch does absolutely nothing to the branch in any interface except for Bitbucket.

You are right, closing a branch in Bitbucket does not delete it from your local repository. It does, however, delete it from the remote repository on bitbucket.org.

The branches you see in SourceTree are most likely branches on your local repository. Bitbucket does not (and should not) have access to your local repository, which is why the branches are still present there. As @Tom Roche mentioned, this is typical behaviour for a DVCS such as git.

It's a good practice to clean up/close branches on the remote if they are no longer needed for a few reasons:

  • it keeps the branch list useful for all users/contributors of the repository
  • it ensures the repository retains good performance of any git operations (having excessively many refs can impact performance)

You are free to delete the branch from your local repository any time you like, either using SourceTree or the command line. 
There are various scripts which will find merged branches and delete them from your local repository, I suggest you look those up if you have quite a few old branches in your local repository.  

For more information on using git and best practices, you can check out the Atlassian 'Getting Git Right' site. 

I hope that helps, 

Felix

 

Deleted user Mar 30, 2016

I do not want to sound dumb but the branch is not deleted from Bitbucket.org.  If you get a complete list of the branches from origin, the branch will still be there.  You can even checkout the branch again, because I have done it.  (I just did it again to make sure I was not wrong.)     

Like # people like this
Felix Atlassian Team Mar 30, 2016

I have just tested this and for me the branch is definitely deleted from bitbucket.org. Note that even if you're listing remote branches in your local repository, git will show you the local tracking branch for the remote branch.

So again, it is in your local repository. If you do not see the branch in Bitbucket's branch list, it has been deleted on the remote. 

Running a git remote prune as @shabbaranks suggests will remove the tracking branch from your local repository as well. 

 

did you do a git fetch before? otherwise it doesn't know about the deletion ...

I am seeing the same thing. I select "delete source branch after merging" when merging my pull request. The remote branch no longer shows up on bitbucket in the bowser, but it is very much still there in SourceTree, just cluttering up my revision history.

Atlassian, can you make it so that your "delete source branch after merging" button actually does what it's intended to do?

I tend to use:

git remote prune origin

 This gets rid of all the local repository branches that are not on the origin.  See: git docs: git-remote.

 

@Dale Cook: 'selecting to close the branch does absolutely nothing to the branch in any interface except for Bitbucket.'

I don't work for Atlassian, and don't use SourceTree, but I have used `git` and other distributed version control systems (DVCS) for awhile. ISTM this is working as designed, and that you need to learn about how DVCS work, particularly the differences between distributed and centralized version control.

@Dale Cook: 'Because Bitbucket does not delete the branch, what is the suggested method for deleting these branches'

Again, I don't know how one does this in SourceTree, but in good old-fashioned command-line `git` (or in the awesome Emacs package=`magit`) one would

  1. delete the branch in your local repository (i.e. in SourceTree)
  2. push the change to your remote repo (i.e. Bitbucket)

 

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Bitbucket

New improvements to user management in Bitbucket Cloud 👥

Hey Community! We’re willing to wager that quite a few of you not only use Bitbucket, but administer it too. Our team is excited to share that we’ll be releasing improvements throughout this month of...

3,725 views 10 16
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you