Git archive: export your project cleanly
git archive creates an archive (zip, tar) of your project without the .git folder. Ideal for delivering code, creating releases, or sharing without history.
What is git archive?
git archive creates an archive of your project from a commit, tag, or branch. The archive contains your files without the .git folder.
It is like packaging your code: you choose the version to package and Git creates a clean zip or tar, ready to be delivered or shared.
Git archive syntax
git archive --format=zip -o f.zip HEADZIP archive of HEAD
git archive --format=tar.gz -o f.tar.gz v1.0tar.gz archive of a tag
git archive --prefix=project/ HEADWith a root folder in the archive
Git archive in practice
Creating zip and tar archives of your project.
ZIP archive
TAR archive and subdirectory
git archive vs regular zip
git archive
Automatically excludes .git, respects export-ignore, can target a specific tag/commit.
regular zip
Includes everything including .git, node_modules, and ignored files.
Common mistakes with git archive
Including sensitive files
If .env is in the repo, it will be in the archive. Use .gitattributes with export-ignore to exclude sensitive files.
Forgetting --prefix
Without prefix, files are at the root of the archive. Add --prefix=project-name/ to put them in a folder (don't forget the trailing /).
Archiving uncommitted files
git archive only takes committed files. Uncommitted changes will not be in the archive. Commit or stash first.
Part of the Git Advanced guide
GitQuest is created by Anaïs (nouvelle fenêtre), web developer and head of education, specializing in tech training and digital accessibility.
Questions about git archive
Deliver your code with GitQuest
Learn to create clean releases and deliver your code with confidence.
Start the investigations