I want to delete a branch both locally and remotely.
$ git branch -d
To delete your branch locally and remotely
Checkout to master branch - git checkout master
Delete your remote branch - git push origin --delete <branch-name>
Delete your local branch - git branch --delete <branch-name>
Deleting Branches
Let's assume our work on branch "contact-form" is done and we've already integrated it into "master". Since we don't need it anymore, we can delete it (locally):
$ git branch -d contact-form
And for deleting the remote branch:
git push origin --delete contact-form
You can also do this using git remote prune origin
$ git remote prune origin
Pruning origin
URL: git@example.com/yourrepo.git
* [pruned] origin/some-branchs
It prunes and deletes remote-tracking branches from a git branch -r
listing.
Since January 2013, GitHub included a Delete branch button next to each branch in your "Branches" page.
Relevant blog post: Create and delete branches
You can also use the following to delete the remote branch
git push --delete origin serverfix
Which does the same thing as
git push origin :serverfix
but it may be easier to remember.
This won't work if you have a tag with the same name as the branch on the remote:
$ git push origin :branch-or-tag-name
error: dst refspec branch-or-tag-name matches more than one.
error: failed to push some refs to 'git@github.com:SomeName/some-repo.git'
In that case you need to specify that you want to delete the branch, not the tag:
git push origin :refs/heads/branch-or-tag-name
Similarly, to delete the tag instead of the branch you would use:
git push origin :refs/tags/branch-or-tag-name