Archiving Git branches

If you have a Git branch that you want to keep but don’t want it hanging around like a fart in a Russian space station, then archiving is the answer. This can be achieved by tagging the branch with the archive tag, before deleting the branch locally and remotely.

The branch can then be restored from the tag at any point in the future.

Here are the steps to achieve this:

 git tag archive/<branchname> <branchname>
 git branch -D <branchname>
 git branch -d -r origin/<branchname>
 git push --tags
 git push origin :<branchname>