How can I archive git branches?

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.

Leave a Comment