Git Archive

By Xah Lee. Date: . Last updated: .

git archive lets you create a copy of your git dir, without the .git data, in zip or tar.gz format.

Git archive is useful if you want to backup a git repository without git history. Because copying thousands small files to a backup drive is super slow. Copying 1 large file is much faster.

First, cd to your git repo, do a commit, then, do:

git archive -o ../myArchive.zip HEAD

or

Note, when you unzip or untar the files, all files will come out in the current dir. So, you better create a dir, put the zip or tar file in it, then unzip or untar.

For zip, you can use this

zip -d xyz some.zip → unzip content to a new parent dir xyz.

without cd to git repo

You can call git command without first cd to the repo. Example:

git --git-dir=/Users/joe/projectX/.git/ archive -o projectX.zip HEAD

Using Just Zip to Archive

creating a zip archive without “.git” dir.

zip -r webbackup.zip /Users/xah/web/ -x \*/.git/\*

If you have a question, put $5 at patreon and message me.

git