Export your git branch to a zip folder

Today I found myself in a sit­u­a­tion where my git host was down and I wanted to share my project with a col­league. The eas­i­est way to do so is to use the git archive com­mand to export the branch to a zip file.

NOTE: This exports the HEAD on the branch spec­i­fied but not the branch history

git archive --format zip --output "output.zip" master

If you need the branch his­tory, just use the reg­u­lar zip com­mand and zip your .git directory

On Ubuntu, you can go to your project direc­tory, then do the following

zip -r my_roject.zip .git

To use the zip file, copy it to another direc­tory, and do the following

unzip my_project.zip -d my_project_copy
cd my_project_copy
git reset --hard HEAD

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *