Git Commands: Delete Branch (Locally and Remote)

Delete a remote branch

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

$ git push origin : # Git versions older than 1.7.0

Delete a local branch

$ git branch --delete

$ git branch -d # Shorter version

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

Delete a local remote-tracking branch

$ git branch --delete --remotes /

$ git branch -dr / # Shorter

$ git fetch --prune # Delete multiple obsolete tracking branches

$ git fetch -p # Shorter

Note:

Delete a branch with git branch -d . 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. The branch is now deleted locally.