Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Version control: delete branches after merging?

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.

like image 549
Nathan Long Avatar asked Mar 24 '10 19:03

Nathan Long


3 Answers

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.

like image 190
Nathan Long Avatar answered Oct 29 '22 05:10

Nathan Long


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.

like image 36
Yaroslav Avatar answered Oct 29 '22 06:10

Yaroslav


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

like image 24
thelost Avatar answered Oct 29 '22 06:10

thelost