I was recently asked to export as a .zip
file one of my projects on my Git repository.
I have actually never had to do this in the 4 years I have been using Git.
I would prefer an answer that is all done inside command line terminal.
git archive --format=zip --output /full/path/to/zipfile.zip master
git archive --format=zip --output project.zip HEAD
, but I still checked the answer off as it did bring me dramatically closer to the solution.
HEAD
parameter at the tail-end. What is the difference between having HEAD
with not?
Jan 17 at 3:59
git archive
will infer format from the output file, reducing the command to git archive -o project.zip master
.
Feb 8 at 3:47
# zip archive
git archive -o output.zip master
# tape archive
git archive -o output.tar master
# tarball
git archive -o output.tar.gz master
According to the official documentation, the -o
option is capable of identifying the target compression format through the extension file name.
Any other unidentified format will be defaulted to the tape archive which is equivalent to:
--format=tar
Following code might help if you want to include .git/ too and don't want to include other extra files which haven't been tracked by git. Suppose the path of your git project is /opt/helloworld/, commit whatever are left, then you can do as the following:
git clone /opt/helloworld/ folder2
cd folder2
tar -czf helloworld-latest.zip folder2
gitignore
d files, and there might be some secrets in it.
.git
usually isn’t a good idea, since it could have arbitrary leftover state in it (maybe secrets too?). You should use git bundle
to transfer a repository in most cases.