tags:

views:

135

answers:

4

I'm relatively new to Git, and want to get advice on best practices for deleting branches.

After I've created and merged a branch back into master, should I leave it hanging around for historical purposes, or should I delete it as soon as it's no longer needed for housekeeping purposes?

+1  A: 

As I see it, there's really no need to keep it around. Unless you --squash the merge, you will have that branch's history in master. I'd go ahead and delete ones you no longer need.

ABach
A: 

Nuke it from orbit. You only really have to care when your delete will remove stuff that isn't in the history of your head branch... and even then I do that quite often if I started testing something and decided it was worthless.

Autocracy
+2  A: 

Delete topic branches (like "fix-iss05") as soon as you merge them back into your master or development branch. Depending on your workflow, you may want to do all work and merges on a "development" branch, and only merge changes to master after they've been tested and are ready to release.

For a great read on git workflow, check out: http://geewax.org/2009/11/21/agile-git-workflow.html

Trevor Hartman
+2  A: 

Typically, you delete a branch after a merge.

For example, after the following merge, you would delete the branch iss53, as you don't need to develop from that branch anymore. You can later recreate it at any moment using the sha1 value of the commit by git checkout -b <name> <sha1>.

(Branches are only necessary when they point to commits that are "tips" of the tree. In fact, in that case, git won't let you remove it, unless you force it to.)

alt text

(the image above comes from the excellent progit book)

Olivier