Git Archive
In one line
git archive exports a tree (commit, branch, or path) as a tar or zip file, without the .git directory.
In simple words
git archive creates a tar or zip archive of a Git tree — a commit, branch, tag, or path — without the .git directory or history. It is the way to export a clean snapshot of the repo at a specific point, suitable for distribution, deployment, or handing to someone who does not need the history.
You specify the format with --format=tar or --format=zip, the output file with -o, and the tree-ish (commit/branch/tag) and optional paths. The archive contains the working-tree contents at that revision, respecting .gitattributes export-ignore rules to exclude files you do not want to ship.
Use cases: creating a release tarball (git archive v1.0 -o release-1.0.zip), deploying a specific commit to a server without cloning, and giving a contributor a snapshot to start from. It is faster and cleaner than cloning and deleting .git.
Example
# Export the main branch as a zip
git archive --format=zip -o project.zip main
# Export a specific tag as a tarball
git archive --format=tar -o release-1.0.tar v1.0
# Export only a subdirectory
git archive --format=zip -o web.zip main:packages/web
# Pipe to gzip for a .tar.gz
git archive --format=tar v1.0 | gzip > release-1.0.tar.gzarchive packs a tree into a tar/zip without .git or history. :path limits to a subdirectory. export-ignore in .gitattributes excludes marked files.
Related terms
Related Resources
Related Lessons
- Git Advanced
Learn git archive.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.