Git Archives - Zip files & Branch backups20 February 2014
If you've popped up across this post, you must have been looking for Git Archives, or something somewhat related. The two main reasons I see for looking for archiving files with git are the following:
- You're looking to keep a backup maybe a zip file, to possibly send to someone.
- It's a project you're not really working on, and would like to clean up your repository.
I'll start off by catering for the first scenario, here you should make use of the official
git archive functionality.
git archive --format zip --output /path/to/zipfile.zip branch
What the above command does is create a zip file representative of your branch (master or any branch you'd like to archive) and puts it in the indicated path. Perfect for compressing different branches, and sending them over to third parties for confirmation.
However having said that, the above might not necessarily be the ideal way to tackle work which has been put on hold. Or possibly discarded, we all know that at times work which you had done before, is recalled back time later. Having a good quality workflow will help with this (more on workflow at a later stage).
What I'd recommend for work which is in git, and needs to be archived is to actually have it reside in a separate branch. Yes leave the 'git archive' in a separate branch. You'd ask but how will I actually recognise what this work is for, the trick is to leave a note indicative of what the branch is for.
Git notes are not the most famous, or the easiest thing to work with, however they can be a very neat way of managing archived projects, especially within a web / agile environment where releases are done quite frequently. What I tend to use to keep things even cleaner, is to use git web, basically it's a cgi script which allows you to view all git projects you're working on, a visual view of the commits as well as branches existing within each repository. Here I've patched up the original script, and had each branch output a description which I've opted to link to our task management system, so I can find a full description screenshots included which perfectly explain what each branch is about.
When it eventually comes to re-integrate the changes, you would
git rebase master, this way you've got all your changes on top of the latest production stuff. You can run again some tests and you'll be ready to merge your changes into master and release back to production. Had you just taken a zip, and deleted the branch, this would have been a far more complex process.
In the next post I'll give more information of how to use git notes, as well as the patch for git web in order to show the branch notes. Feel free to leave comments and discuss these thoughts.