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 r
I am using following aliases to hide archived branches:
[alias]
br = branch --no-merge master # show only branches not merged into master
bra = branch # show all branches
So git br
to show actively developed branches and git bra
to show all branches including "archived" ones.
My approach is to rename all branches I don't care about with a "trash_" prefix, then use:
git branch | grep -v trash
(with a shell key binding)
To retain the coloring of the active branch, one would need:
git branch --color=always | grep --color=never --invert-match trash
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.
To archive and delete the branch:
git tag archive/<branchname> <branchname>
git branch -d <branchname>
To restore the branch some time later:
git checkout -b <branchname> archive/<branchname>
The history of the branch will be preserved exactly as it was when you tagged it.
Extending Steve's answer to reflect the changes on the remote, I did
git tag archive/<branchname> <branchname>
git branch -D <branchname>
git branch -d -r origin/<branchname>
git push --tags
git push origin :<branchname>
To restore from the remote, see this question.
Jeremy's answer is correct in principle, but IMHO the commands he specifies are not quite right.
Here's how to archive a branch to a tag without having to checkout the branch (and, therefore, without having to checkout to another branch before you can delete that branch):
> git tag archive/<branchname> <branchname>
> git branch -D <branchname>
And here's how to restore a branch:
> git checkout -b <branchname> archive/<branchname>