Sometimes you just want to distribute the source code without its history, and that’s where git-archive comes in. git-archive will create an archive of the files at any point in the history and wrap them all up for you in a tar or zip (defaults to tar). You can even make an archive from a remote repo by using the
option in the administrator has enabled it.
You’ll typically use git-archive like this:
git archive <tree-ish> > my_new_archive.tar
And that will create an archive of everything in your repo. If you just want an archive of some specific files you can simply pass in the path(s) to the file(s) you want in the archive after your tree-ish. If you wanted to create a zip file instead of a tar you’d simply pass it the “—format=zip” option.
Many people wonder if there is a way to check out just the tip of the repo so that they don’t have to download the entire revision history. This is called a “shallow” clone and is possible by passing the “
--depth <some\_number\>” but it has a number of limitations: you can’t clone, or fetch from it and you can’t push from or into it, but it’s useful if you only want to look at, or near, the tip of a large project with a long revision history and would want to send in your fixes or features as patches.