How to delete a Git branch both locally and remotely?


Deleting a local branch:

git branch --delete <branch>  
git branch -d <branch>        # Shorter version
git branch -D <branch>        # Force delete un-merged branches

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

Deleting a local remote-tracking branch:

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

git fetch <remote> --prune # Delete multiple obsolete tracking branches
git fetch <remote> -p      # Shorter


Delete Local And Remote Branch

  1. To delete the local branch.

The -d option is an alias for —delete, which only deletes the branch if it has already been fully merged in its upstream branch. You could also use -D, which is an alias for —delete --force, which deletes the branch “irrespective of its merged status.”

git branch -d branch_name
  1. To delete remote branch

As of Git v1.7.0, you delete a remote branch using:

git push origin --delete <branch_name>

Before Git v1.7.0, you delete remote branches using:

git push origin :<branch_name>