Deleting a branch LOCALLY Delete a branch with git branch -d <branch> . The -d option will delete the branch only if it has already been pushed and merged with the remote branch. Use -D instead if you want to force the branch to be deleted, even if it hasn't been pushed or merged yet.
You have to change the main branch of bibucket before being able to delete it. As long as master is the main branch, bitbucket will prevent you to do so (which make sense).
- First, on your local repository, perform git reflog . This will list down all previous HEADs. Find the latest commit hash for the branch that you have deleted.
Deleting Multiple Remote Branches egrep -v "(^\*|master|main)" - exclude branch master and main. sed 's/origin\///' - because the remote branches are prefixed with origin/ this command will filter that part out so it returns only the branch name. xargs -n 1 git push origin --delete - deletes the remaining branches.
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!
For deleting branch from Bitbucket,
In addition to the answer given by @Marcus you can now also delete a remote branch via:
git push [remote-name] --delete [branch-name]
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.
in Bitbucket go to branches in left hand side menu.
Step 1 : Login in Bitbucket
Step 2 : Select Your Repository in Repositories list.
Step 3 : Select branches in left hand side menu.
Step4 : Cursor point on branch click on three dots (...) Select Delete (See in Bellow Image)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With