Git Archive; Zip Git Repo Without .git

By Xah Lee. Date: . Last updated: .

What is Git Archive

git archive creates a copy of your git repository 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.

Create Git Archive

First, do a commit of your project.

cd to your git repo, then do one of:

# archive to zip
git archive -o ../myArchive.zip HEAD

# archive to tar.gz
git archive -o ../myArchive.tar.gz HEAD

Create Archive Without Cd to Git Repo

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

# the --git-dir must point to the .git dir
# the archive path must be archive file name/path ending in .zip
git --git-dir="c:/Users/xah/git/xahemacs/.git" archive -o "c:/Users/xah/Documents/xahemacs_2022-08-07.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: Zip 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

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

git