Summary

Gits branches are so lightweight that its easy to create them whenever you better.

But its also easy to end up with leftover branches you no longer need.

So whats involved in deleting a branch?

Branch being pruned

Maksim Safaniuk/Shutterstock

Why Delete a Branch?

This is fine since branching is a lightweight operation; its very fast and uses disk space efficiently.

As a result, many git development workflows encourage branching, even for very small or short tasks.

A list of git branches showing two local and three remote

For example, a common strategy is tocreate a separate branchfor each and every bug fix.

Deleting branches should be just as much a part of your everyday workflow as creating them is.

Therefore, git will refuse to delete such a branch by default.

A command line showing the removal of a git branch using ‘git branch -d’

Youll use thegit pushcommand along with the-dflag to delete.

maineven though git itself supports this.

If the default branch is the one that is currently active, the app disables the menu action.

A git error message explaining that the main branch cannot be deleted

You must delete each separately.

Hover over the appropriate branch name and click theBranchactions menu which looks like three vertical dots.

The app displays local and remote branches in a panel on the left-hand side.

A git error message explaining that an unmerged branch cannot be deleted

As with the GitHub Desktop app, the GitHub website will not allow you to delete the default branch.

If you try, youll see an warning pop-up:

Deleting any other branch, however, is straightforward.

However, since it will always represent a remote branch, this behavior should make sense.

A git error message explaining that the deleted branch has been merged to the remote, but not HEAD.

Note that, after deleting, youll see a button toRestorethe branch.

However, this is simply a useful undo feature, just in case you poke the delete icon accidentally.

Bitbucket calls this theMain branchinRepository controls.

The git command line removing a remote branch.

But for simple day-to-day development, youre likely to be creating and deleting local branches all the time.

This is a core aspect of a typical git workflow you should become accustomed to.

A screenshot showing how to delete a branch using GitHub desktop

A screenshot showing a remote branch being deleted in GitHub Desktop

Deleting a local branch using GitKraken

A screenshot of GitKraken showing a warning when attempting to delete a branch

A screenshot of GitKraken showing an error when attempting to delete the current branch

A screenshot showing how to delete a local branch in Tower

A screenshot showing the confirm dialog in Tower when deleting a branch

A GitHub error message explaining that you cannot delete the default branch.

A screenshot of the Branches page on GitHub

A screenshot of GitHub showing the effects of a branch having been deleted

A screenshot showing a Branch Actions menu on Bitbucket

A screenshot showing multiple branches being deleted on Bitbucket