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

Click any option to expand

Beginner (3)

Write the archive to this file; the format is taken from its extension.

RecommendedWrite the archive to a file

Example

git archive -o shop.zip HEAD

Put every file under this folder inside the archive (end it with /).

RecommendedUnpack into one tidy folder

Example

git archive --prefix=shop-1.0/ -o shop.tar.gz v1.0

List the available formats.

When neededSee the supported formats

Example

git archive --list

Choosing the Right Option

archive vs bundle

Files or history?

CommandContainsUse for
git archiveThe files of one commitDownloads, deployments
git bundleCommits and branchesMoving a repository offline

Examples

Zip a release

git archive -o shop-1.0.zip v1.0

Files of v1.0 in a zip.


Tar with a folder

git archive --prefix=shop/ -o shop.tar.gz HEAD

Everything 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.0

Export 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.