Git Archive; Zip Git Repo Without .git
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 ../xName.zip 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/xproj_2022-08-07.zip" 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 xbackup.zip /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 some.zip