tags:

views:

195

answers:

2

I have some old branches in my git repository that are no longer under active development. I would like to archive the branches so that they don't show up by default when running git branch -l -r. I don't want to delete them, because I want to keep the history. How can I do this?

I know that it's possible to create a ref outside of refs/heads. For example, refs/archive/old_branch. Are there any consequences of doing that?

+4  A: 

You could archive the branches in another repository. Not quite as elegant, but I'd say it's a viable alternative.

git push git://yourthing.com/myproject-archive-branches.git yourbranch
git branch -d yourbranch
August Lilleaas
You can create `git-bundle` instead of separate repository.
Jakub Narębski
+10  A: 

I believe the proper way to do this is to tag the branch. If you delete the branch after you have tagged it then you've effectively kept the branch around but it won't clutter your branch list.

If you need to go back to the branch just check out the tag. It will effectively restore the branch from the tag.

$> git tag archive/<branchname> #branch snapshot is archived
$> git branch -d <branchname>   #branch is deleted
<...> #time passes
$> git checkout archive/<branchname> # now the branch is restored from the snapshot

The history of the branch will be preserved exactly as it was when you tagged it. So this should do the trick. It's basically what Jakub was saying in the comments above.

Jeremy Wall