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.

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 ../ HEAD
# archive to tar.gz
git archive -o ../xName.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/xproj/.git" archive -o "c:/Users/xah/" HEAD

Git Clone Without History

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

Using Just Zip to Archive

creating a zip archive without “.git” dir.

zip -r /Users/joe/xproj/ -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