Techy and Trustable

Archive a Git Superproject and Its Submodules

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.

If you haven’t installed python, see this page. If you are working on Windows, there is also a video on Youtube teaching you how to install python on Windows.

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:

git-archive-all [archive-file-name.format]

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]

For example:

git-archive-all my-archive.tar.gz

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]

For example:

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.

More

The git-archive-all script has some other powerful features. If you are interested, please visit its homepage.