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
Yes, you can create a ref with some non-standard prefix using git update-ref. e.g.
git update-ref refs/archive/old-topic topic && git branch -D topicgit branch topic refs/archive/old-topicRefs with non-standard prefix (here refs/archive) won't show up on usual git branch, git log nor git tag. Still, you can list them with git for-each-ref.
I'm using following aliases:
[alias]
add-archive = "!git update-ref refs/archive/$(date '+%Y%m%d-%s')"
list-archive = for-each-ref --sort=-authordate --format='%(refname) %(objectname:short) %(contents:subject)' refs/archive/
rem = !git add-archive
lsrem = !git list-archive
Also, you may want to configure remotes like push = +refs/archive/*:refs/archive/* to push archived branches automatically (or just specify on push like git push origin refs/archive/*:refs/archive/* for one-shot ).
Another way is to writing down SHA1 somewhere before deleting branch, but it has limitations. Commits without any ref will be GC'd after 3 months (or a couple of weeks without reflog), let alone manual git gc --prune. Commits pointed by refs are safe from GC.
Edit: Found a perl implementation of the same idea by @ap: git-attic
Edit^2: Found a blog post where Gitster himself using the same technique. He named it git hold.