Delete branches in Bitbucket
Asked Answered
H

12

180

I've created lots of branches in one of our repositories. Those branches are for testing before it will be pulled to the master. Now I see lots of them on the list and they we will never use it again. How to delete those branches directly to Bitbucket?

Heracliteanism answered 1/3, 2013 at 4:46 Comment(0)
A
287

If the branches are only local, you can use -d if the branch has been merged, like

git branch -d branch-name

If the branch contains code you never plan on merging, use -D instead.

If the branch is in the upstream repo (on Bitbucket) you can remove the remote reference by

git push origin :branch-name

Also, if you're on the Bitbucket website, you can remove branches you've pushed by going to the Feature branches tab under Commits on the site. There you'll find an ellipsis icon. Click that, then choose Delete branch. Just be sure you want to drop all the changes there!

enter image description here

Agamic answered 5/3, 2013 at 16:45 Comment(4)
If I run 'git branch -r', I notice that BB isn't deleting the branch from the server. It no longer shows up in the GUI, but its shows on the git server.Objectivity
There are some branches that BitBucket simply will not allow deleting.Cruciferous
Looks like not allowing for me: remote: external-pre-receive-hook declined remote: fatal: not a tree object remote: tar: This does not look like a tar archive remote: tar: Exiting with failure status due to previous errorsBisitun
@jerseybean - git remote prune origin should help you out. I'm 2 years later but hopefully it will help someone.Entrain
M
62

For deleting branch from Bitbucket,

  1. Go to Overview (Your repository > branches in the left sidebar)
  2. Click the number of branches (that should show you the list of branches)
  3. Click on the branch that you want to delete
  4. On top right corner, click the 3 dots (besides Merge button).
  5. There is the option of "Delete Branch" if you have rights.
Midship answered 11/8, 2015 at 9:22 Comment(2)
Where is 'overview'? If you mean Source, I see no 'Delete Branch' option under the ...Ethics
Step 1 should be "go to your repo and click 'branches' in the left sidebar."Orpine
L
28

In addition to the answer given by @Marcus you can now also delete a remote branch via:

git push [remote-name] --delete [branch-name] 
Lacombe answered 27/7, 2016 at 21:47 Comment(0)
C
16

I could delete most of my branches but one looked like this and I could not delete it:

enter image description here

Turned out someone had set Branch permissions under Settings and from there unchecked Allow deleting this branch. Hope this can help someone.

enter image description here

Update: Where settings are located from question in comment. Enter the repository that you wan't to edit to get the menu. You might need admin privileges to change this.

enter image description here

Carmichael answered 24/2, 2017 at 9:16 Comment(2)
Where can one find the "Settings"? I have to delete the main branch or all the files in it. How do I do it?Neddy
That's on Bitbucket websiteOdle
B
14

In Bitbucket go to branches on the left hand side menu.

  1. Select your branch you want to delete.
  2. Go to action column, click on three dots (...) and select "delete branch".
Bactria answered 20/9, 2017 at 6:3 Comment(0)
X
9

In Bitbucket go to your project, click branches , click on the three points and click delete multiple.

This option for mass delete.

enter image description here

Xenon answered 8/9, 2021 at 13:0 Comment(0)
E
3

I've wrote this small script when the number of branches in my repo exceeded several hundreds. I did not know about the other methods (with CLI) so I decided to automate it with selenium. It simply opens Bitbucket website, goes to Branches, scrolls down the page to the end and clicks on every branch options menu -> clicks Delete button -> clicks Yes. It can be tuned to keep the last N (100 - default) branches and skip branches with specific names (master, develop - default, could be more). If this fits for you, you can try that way.

https://github.com/globad/remove-old-branches

All you need is to clone the repository, download the proper version of Chrome-webdriver, input few constants like URL to your repository and run the script.

The code is simple enough to understand. If you have any questions, write comments / create an Issue.

Epilimnion answered 20/6, 2019 at 17:22 Comment(0)
D
2

If you are using a pycharm IDE for development and you already have added Git with it. you can directly delete remote branch from pycharm. From toolbar VCS-->Git-->Branches-->Select branch-->and Delete. It will delete it from remote git server.

Dorolisa answered 17/9, 2018 at 7:35 Comment(0)
M
1

Try this command, it will purge all branches that have been merged to the develop branch.

for i in `git branch -r --merged origin/develop| grep origin | grep -v '>' \
   | grep -v master | grep -v develop | sed -E "s|^ *origin/||g"`; \
do \
   git push origin $i --delete; \
done
Mineralogist answered 27/3, 2019 at 11:51 Comment(0)
E
0

In Android Studio, the options down the right corner of the IDE:

  • Change/checkout other local branch
  • Delete unwanted local branches (i.e. v0.0.1...)
  • Delete unwanted remote branches (i.e. origin/v0.0.1...) -- this step will delete branches in BitBucket if the branches are not prevented to be deleted and they are not the MAIN BRANCH.
Erode answered 9/11, 2015 at 23:20 Comment(0)
B
0

In bitbucket web console., delete branch is disabled when there are active Pull requests.

Burrows answered 4/3, 2022 at 6:24 Comment(0)
H
0

This one will surely work and is easy to do.

  1. Open your repository in stash/bitbucket url of your repo on browser.
  2. On the left bottom, if >> arrow is present, click on it.
  3. Now scroll down/up, till you find Branches text/link in the left menu and click on it.
  4. In dropdown or search box, type your branch name to search till it appears in the list below.
  5. The last column in the list with ...(3 dots) and header as Actions, click on the same and click on "Delete branch".

Note: Ensure that you click the dots / delete your own branch that you intend to do.

Hofuf answered 4/8, 2023 at 11:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.