Last updated on October 1, 2016
While Git is a powerful and popular Distributed Version Control System, Git’s Submodule feature and Archive feature make Git even more powerful. However, the two features seems not working together well: Git’s archive command does not provide a way to archive a Git repository and all of its submodules (yet). Fortunately, many scripts that could do this for us are available online, but not all of them work like a charm. After browsing the Internet and trying them one by one, I found this python script every useful. It has helped me and I believe it will also bring you luck.
Install Python If You Don’t Have It Installed
Skip this paragraph if you know you have installed Python
Since this script is written in Python, you need to install python first — however, probably you don’t need to do so, since most Linux distributions have it installed by default. If you are unsure whether Python is installed on you computer, run
python --version in your shell. If you see a version number printed, that means you have installed Python.
Download git-archive-all and Use It
If you are working on a UNIX-like system
Give this file execute permission:
chmod +x git-archive-all
Then copy this script to one of your directories in the PATH environment variable and switch your working directory to the root directory of your Git repository. Run the following command to archive the Git repository and its submodules:
If the above command does not work (probably because your Python interpreter executable is installed somewhere other than /usr/bin), try:
python /path/to/git-archive-all [archive-file-name.format]
Then a compressed file my-archive.tar.gz will show up in your working directory. You don’t need to specify a compression format like the Git’s Archive command—git-archive-all will decide the format based on the suffix of your file name, such as tar.gz, zip.
For Homebrew users on Mac OS X: Simply run
brew install git-archive-all to finish the installation. Then use
git-archive-all command as above.
If you are working on Windows
Copy this script somewhere, launch Command Prompt and switch the working directory to the root of the Git repository. Then use the following command to archive the Git repository and its submodules:
python X:\\path\to\git-archive-all [archive-file-name.format]
python C:\\python_scripts\git-archive-all my-archive.zip
Then a compressed file my-archive.zip will show up in your working directory. You don’t need to specify a compression format like the Git’s Archive command — git-archive-all will decide the format based on the suffix of your file name, such as tar.gz, zip.
The git-archive-all script has some other powerful features. If you are interested, please visit its homepage.