Two scenarios come up regularly when working with remote git branches, and I always end up looking them up. Here they are in one place.
Deleting a local branch from the remote Link to heading
You’ve deleted a branch locally and now want to remove it from the remote repository as well:
git push <remote> :<deleted_branch>
# Example:
git push origin :my-feature-branch
The colon prefix tells git to push “nothing” to the remote branch, effectively deleting it. A more explicit alternative (git 1.7.0+):
git push <remote> --delete <deleted_branch>
Pruning stale remote-tracking refs Link to heading
Someone else deleted a branch on the remote, but your local git still lists it under git branch -r. To remove all stale remote-tracking refs for a given remote:
git remote prune <remote>
# Example:
git remote prune origin
You can also do this automatically on every fetch by setting fetch.prune:
git config --global fetch.prune true
With that option set, git fetch will always clean up stale remote-tracking branches, so no need to run git remote prune manually.