git archive
Administration
Export the files of a commit as a zip or tar archive
The 'git archive' command writes the files of a commit, tag or branch into a zip or tar archive — without the history and without the .git folder. It is the standard way to publish a release as a download. The format follows the output file extension, and --prefix puts every file inside a folder.
Synopsis
git archive [--format=<fmt>] [--list] [--prefix=<prefix>/] [-o <file>] <tree-ish> [<path>...][ ] optional| or<arg> placeholder... repeatable--flag option
Options
Choosing the Right Option
archive vs bundle
Files or history?
| Command | Contains | Use for |
|---|---|---|
git archive | The files of one commit | Downloads, deployments |
git bundle | Commits and branches | Moving a repository offline |
Examples
Zip a release
git archive -o shop-1.0.zip v1.0Files of v1.0 in a zip.
Tar with a folder
git archive --prefix=shop/ -o shop.tar.gz HEADEverything inside shop/.
One folder only
git archive -o docs.zip HEAD docs/Only the docs folder.
Workflow Examples
1
git tag -a v1.0 -m "Release"Tag it
2
git archive --prefix=shop-1.0/ -o shop-1.0.zip v1.0Export it
Troubleshooting
Some files are missing
Cause: Untracked or ignored files are never archived
Commit them, or check .gitattributes export-ignore rules
Tips & Pitfalls
Best Practices
- ✓Archive tags, not branches, so the download matches the release.
Common Mistakes
- ✗Expecting history in the archive — use git bundle to move history.
- ✗Forgetting -o and filling the terminal with binary data.
FAQ
A:
Yes: mark them export-ignore in .gitattributes.