Skip to content

Instantly share code, notes, and snippets.

@hsribei
Created October 25, 2011 18:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hsribei/1313664 to your computer and use it in GitHub Desktop.
Save hsribei/1313664 to your computer and use it in GitHub Desktop.
It's OK to delete branches after merging them

Deleting branches after merging them into other branches can help unclutter your list of branches. If you use a lot of topic branches for features and don't delete them, pretty soon you'll have a very long list of old, unmaintained branches, and that's going to make it harder for you to find the ones you're currently working on.

You can always get back to old branches anyway. When you merge, a merge commit is created on the branch you merged into. Merge commits have two parents, which are referenced by their SHA1s. So if you need to see the old branch, just check out the SHA1 of the corresponding parent on the merge commit. Since it's referenced in a living branch, it's not gonna get garbage-collected by Git.

The only case where the original SHA1 wouldn't be kept around is if it was a fast-forward merge. To prevent that from happening, you can use the option --no-ff on the git merge command, which will create a merge commit even when a fast forward would be possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment