Back

Explore Courses Blog Tutorials Interview Questions
+2 votes
1 view
in DevOps and Agile by (19.4k points)
edited by

I want to delete a branch both locally and remotely.

Failed Attempts to Delete Remote Branch

$ git branch -d remotes/origin/bugfix

error: branch 'remotes/origin/bugfix' not found.

$ git branch -d origin/bugfix

error: branch 'origin/bugfix' not found.

$ git branch -rd origin/bugfix

Deleted remote branch origin/bugfix (was 2a14ef7).

$ git push

Everything up-to-date

$ git pull

From github.com:gituser/gitproject

* [new branch] bugfix -> origin/bugfix

Already up-to-date.

What should I do differently to successfully delete the remotes/origin/bugfix branch both locally and remotely?

1 Answer

+3 votes
by (27.5k points)

Ways of deleting a remote branch:

$ git push origin --delete <branch>  # Git version 1.7.0 or newer

$ git push origin :<branch>          # Git versions older than 1.7.0

Ways of deleting a local branch:

$ git branch --delete <branch>

$ git branch -d <branch> # Shorter version

$ git branch -D <branch> # Force delete un-merged branches

Ways of deleting a local remote-tracking branch:

$ git branch --delete --remotes <remote>/<branch>

$ git branch -dr <remote>/<branch> # Shorter

Ways of deleting multiple obsolete tracking branches

$ git fetch <remote> --prune 

Shorter version of the same: 

$ git fetch <remote> -p      

by (29.3k points)
This command git branch --delete --remotes <remote>/<branch> helps me a lot for my project.
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94k users

Browse Categories

...