John Turknett.com


Deleting branches in Git

09/25/2014


Deleting branches in Git is something that we all have to do from time to time. It really is an easy task to do but I end up having to search for the syntax to do it every time.

Deleting a local branch
git branch -D [branch_name]

The command really is not that much different than it's counterpart for creating a new local branch.

Creating a local branch
git checkout -b [branch_name]

The problem I always have is with deleting remote branches. Sometimes remote branches live very short lives. We push code to have others look at, then we merge with master. This leaves us with a remote branch to dispose of as it is no longer needed.

Deleting a remote branch
git push origin :[branch_name]

There is a new way to delete branches which will hopefully stick, although I can assure I will still have to look this up as well. The concept of pushing to nothing to a remote branch to delete it makes sense but I also think the git api could be a bit more clear on it's intentions.

Deleting a remote branch
git push origin --delete [branchName]

There you have it. Two ways to delete a remote branch as well as a way to delete a local branch. And lucky you I even threw in how to create a branch with the checkout command.



Related Topics

  • Git