6

Our team has recently moved to Git. I've been burned a couple times because my cod somehow ended up not being in the develop branch like I wanted it to be. Since then I have stopped deleting the branches I make every day to work on code, in case I need those branches later.

I now have many branches that I don't want to look at in SourceTree every day. However, I still want to save those branches just in case. Is there any way I can save my old branches but keep them aside so as not to pollute my Git repository?

usha
  • 28,973
  • 5
  • 72
  • 93
Joe
  • 7,922
  • 18
  • 54
  • 83
  • 3
    possible duplicate of [How can I archive git branches?](http://stackoverflow.com/questions/1307114/how-can-i-archive-git-branches) – CharlesB Oct 21 '13 at 19:13
  • yep, though I'd argue pushing to an archive repo so you can just delete the local branches is the better answer there, for my money excess tags are even more of a pain than excess branches. – jthill Oct 22 '13 at 19:40

4 Answers4

4

Branches are there if you want to keep developing and evolving that branch. If that is not the case and you only keep the branches as 'bookmarks', you should use tags instead (and delete the branches).

That way, git branch -a will look cleaner. And if someday you want to go back and see how that branch looked like, you can always checkout the tag, and eventually recreate a branch based on that tag.

FedeCz
  • 533
  • 3
  • 4
0

One simple thing I can think of is to see if you can configure SourceTree with different views - one to only show the active branch and the other to show all branches.

EDIT: This will still show you all branches that have been merged into the active branch. If you have a lot of old branches in the active branch view, I would question the need for you to keep them anyway. Git does record all commits that lead to your active branch, including merges. Therefore, if the reason you want to keep your old branches around is to see where a bug was introduced, then you're in luck. Just delete all those branches and use git bisect. However, if the reason you want them around is to mark releases, then I would suggest you check out git flow.

The reason I suggest this is that the number of branches is not a problem to git, but to you. If those old branches were to disappear from your view of your repository, they wouldn't bother you. They will not slow down git in any way. The fact that you also want to archive them tells me that you may want to come back and look at them. So just switch between two views of your repository.

I have not used SourceTree extensively, so I don't know if it supports different views. I know gitk does : gitk and gitk --all. I would expect SourceTree to do the same.

Hope this helps.

Carl
  • 43,122
  • 10
  • 80
  • 104
0

In my workflow I delete branches with git -d branchname This will refuse to delete the branch if it is not yet merged into another branch (at least, in my git version, maybe you need to update?), and if it does soso, I keep the branch around for later.

If I am certain I want to absolutely get rid of a branch, I use git -D branchname which will not complain about not being merged.

Jens Timmerman
  • 9,316
  • 1
  • 42
  • 48
0

This still seems to be a matter of preference. I prefer to keep these branches so that by looking at the git log I can easily answer the question "why the code branched a week ago" without reading all the commit messages and trying to understand what unites them.

varepsilon
  • 488
  • 5
  • 8