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.
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
HEAD
parameter at the tail-end. What is the difference between having HEAD
with not? –
Faefaeces git archive
will infer format from the output file, reducing the command to git archive -o project.zip master
. –
Bike master
to main
for 2023 feel? @Unidirectional –
Allaallah # 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. –
Bandsman .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. –
Leduc I personally prefer to create the archive with prefix for the project, otherwise the consumers of the archive will need to create take care of the scoping themselves. Please note that you will need the trailing forward slash for the project directory.
I also prefer shortening as much as possible, so when you have the right suffix for the extension, git will recognise the format automatically.
You can also just use -o
instead of --output
for convenience and rapid typing.
Also, GitHub, etc, prefer to use main instead of master these days.
git archive --prefix foo/ -o ~/foo.zip main
© 2022 - 2024 — McMap. All rights reserved.
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. – Damle