8

When you branch some code, finish working with the branch, and merge it back to the trunk, what do you do with the branch? Delete it from the repository? Keep it for reference?

It seems like you would keep it for reference, but I imagine the /branches directory could get pretty cluttered.

(If this isn't something people generally agree on, please comment and I'll make it a community wiki.)

Clarification

jleedev is right - we should specify which version control system we're talking about.

I had Subversion in mind, but would love to hear responses regarding other systems, too. Please specify which one you're answering about, or, <bribery>if you want to get the accepted answer</bribery>, compare and contrast several systems.

Community
  • 1
  • 1
Nathan Long
  • 122,748
  • 97
  • 336
  • 451
  • 1
    Most of these answers would be improved by a mention of which VCS it applies to, especially Git and the like vs. Subversion. – Josh Lee Mar 25 '10 at 07:17

7 Answers7

9

Answering my own question much later

Now that I use Git, yes, I do delete branches when I'm finished with them. This is because in Git, a branch is nothing more than a label pointing to a specific commit.

When I first heard that, I didn't quite understand, but it's literally true. If you go into a project which you've got under Git version control and open .git/refs/heads, you will see one file for each branch you have, including master. Each file contains the hash of a commit. That's it.

Obviously, creating such a file is very cheap, which is why branching is cheap in Git. That, in turn, is why I can branch often, and it would be silly to have branches like add_bells_to_the_widget piling up everywhere.

Once a branch is merged into master, its commits are part of the master branch's history. The only purpose of keeping the branch would be to know which commit I considered that last one on a branch. And that's not very relevant to me when the code is in production.

Community
  • 1
  • 1
Nathan Long
  • 122,748
  • 97
  • 336
  • 451
  • 1
    Can you please elaborate on "piling up everywhere"? Where, exactly? I've recently started using git for serious work, and trying to establish a decent workflow. You said "keeping the branch would be to know which commit I considered that last one on a branch", and I understand you don't care about it, but the whole purpose of VCS is to remember things you initially think you don't need, and eventually learn you do. What this deletion is exactly buying you? – Davide Jul 20 '12 at 17:27
  • @Davide - for me, `git branch` shows a couple of standard branches (`master` and `dev`) and a list of things I'm working on (`add_new_widget`, `fix_dumb_bug`, etc). That should not be more than a handful of features and/or bugfixes at any given time. More than that is clutter. The deletion keeps me organized. And I'm not losing anything, really; the work and the commits are still in my history; even the names of the branches I merged are there in the merge commits. – Nathan Long Jul 20 '12 at 21:27
  • I see. I thought the name of the branches were gone. I will dig into some log histories to understand this better upfront. Thanks! – Davide Jul 23 '12 at 20:43
  • In mine logs the branch names are gone when I delete them. Since it's becoming pretty long for a comment, I made it a question, please have a look: http://stackoverflow.com/questions/12114519/how-to-get-git-log-display-name-of-deleted-branches – Davide Aug 24 '12 at 18:06
4

I remove reintegrated branches since I do not need them any more. Git and Mercurial keep branching/merging history anyway. In subversion I'd keep old branches to have a reference to commit history.

Yaroslav
  • 2,718
  • 17
  • 16
  • 1
    What do you mean when you say that git maintains branching information. How can you find out if a particular commit was part of the 625 branch if the branch is gone? – Dan Rosenstark Mar 24 '10 at 20:19
  • Branch in git is just a 'pointer' to commit which will be a parent for subsequent commits. When you remove a branch you just delete its pointer, actual commits are not touched. In the history you see that there was a branch and in merge comments you see it's name. – Yaroslav Mar 24 '10 at 21:11
2

I always prefer keeping the branches. Yes, I can use them as reference, or simply retrieve certain version any time.

thelost
  • 6,638
  • 4
  • 28
  • 44
1

SVN users generally tag branches to keep the branches directory clean, no?

Jeremy
  • 22,188
  • 4
  • 68
  • 81
0

In every project I work on we delete the dev branches as soon as we're done with them. We do however branch the code when we release and hold on to those for a while

Rob
  • 1,983
  • 2
  • 20
  • 29
0

I've never deleted branches, but consider it a matter of personal taste. You're not actually deleting the revisions from the repository when you delete the branch.

Anon
  • 345
  • 2
  • 6
0

If there is any chance the branch will have a life of its own, obviously you keep it. If not, i would probably keep it but revoke write access. Disks are cheap.

dicroce
  • 45,396
  • 28
  • 101
  • 140