Skip to main content

Deleting Branches

At some point, you might want to delete a branch. This chapter explains how to do that.

Let's assume our work on "contact-form" is done and we've already integrated it into "master". Since we don't need it anymore, we can delete it:

git branch -d contact-form

Tidy as we are, we also delete the remote branch by using the "git push" command with the "--delete" flag:

git push origin --delete contact-form

We have now removed both the local and remote versions of the branch.


For our teammates, however, the situation might look a bit different:

  • Fetch with "Prune" Option: Although we deleted the remote branch, it might still show up for other members of our team. To make sure that only active branches are displayed in a remote repository, it makes sense to always use the git fetch command with the --prune option:

git fetch origin --prune
  • Local Branches: In case one of our colleagues has created a local branch from the remote version of our contact-form branch, this will of course stay untouched! Deleting a branch on a remote never affects any of the existing local branches.