Reputation: 22808
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?
Upvotes: 184
Views: 420690
Reputation: 153
This one will surely work and is easy to do.
Note: Ensure that you click the dots / delete your own branch that you intend to do.
Upvotes: 0
Reputation: 509
In Bitbucket go to your project, click branches , click on the three points and click delete multiple.
This option for mass delete.
Upvotes: 11
Reputation: 395
In Bitbucket go to branches on the left hand side menu.
Upvotes: 15
Reputation: 545
In bitbucket web console., delete branch is disabled when there are active Pull requests.
Upvotes: 0
Reputation: 5110
For deleting branch from Bitbucket,
Upvotes: 64
Reputation: 301
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.
Upvotes: 3
Reputation: 992
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
Upvotes: 1
Reputation: 23
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.
Upvotes: 2
Reputation: 69968
I could delete most of my branches but one looked like this and I could not delete it:
Turned out someone had set Branch permissions
under Settings
and from there unchecked Allow deleting this branch
. Hope this can help someone.
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.
Upvotes: 16
Reputation: 1529
In addition to the answer given by @Marcus you can now also delete a remote branch via:
git push [remote-name] --delete [branch-name]
Upvotes: 30
Reputation: 4020
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!
Upvotes: 293
Reputation: 2149
In Android Studio, the options down the right corner of the IDE:
Upvotes: 0