How can I delete branches in Git?

Before we look at deleting remote branches, let's discuss the syntax for deleting a local branch in Git.

Deleting local branches in Git

$ git branch -d feature/login

Using the "-d" flag, you tell "git branch" which item you want to delete.

Note that you might also need the "-f" flag if you're trying to delete a branch that contains unmerged changes. Use this option with care because it makes losing data very easy.

Deleting remote branches in Git

To delete a remote branch, we do not use the "git branch" command - but instead "git push" with the "--delete" flag:

$ git push origin --delete feature/login

Deleting both a local and a remote branch

Just a side note: please keep in mind that local and remote branches actually have nothing to do with each other. They are completely separate objects in Git.

Even if you've established a tracking connection (which you should for most scenarios), this still does not mean that deleting one would delete the other, too!

If you want any branch item to be deleted, you need to delete it explicitly.


Tip

Deleting Branches in Tower

In case you are using the Tower Git client, you can simply right-click any branch item in the sidebar and choose the "Deleteā€¦" option to get rid of it:


Learn More

Get our popular Git Cheat Sheet for free!

About Us

As the makers of Tower, the best Git client for Mac and Windows, we help over 100,000 users in companies like Apple, Google, Amazon, Twitter, and Ebay get the most out of Git.

Just like with Tower, our mission with this platform is to help people become better professionals.

That's why we provide our guides, videos, and cheat sheets (about version control with Git and lots of other topics) for free.