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, do a commit of your project.

cd to your git repo, then do one of:

git archive -o ../myArchive.zip HEAD

To archive in .tar or .tar.gz or .tar.xz, just replace .zip with those.

Archive 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

Git Clone Without History

git clone --depth 1 file:////Users/joe/projectX/.git/

Using Just Zip to Archive

creating a zip archive without “.git” dir.

zip -r webbackup.zip /Users/joe/projectX/ -x \*/.git/\*

Warning: unzip bomb

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.

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

git