← All languages
Git command of the day
Random

archive

Create an archive of files from a named tree.

Description

The git archive command creates an archive of the specified format containing the tree structure for the named tree. If a prefix is specified, it is prepended to the filenames in the archive.

This is useful for creating release tarballs or zip files of your project without including the .git directory or any untracked files. The resulting archive contains only the tracked files at the specified revision.

You can archive specific paths within the repository, use different output formats (tar, zip, tar.gz), and apply path-based filters. Remote archives can also be fetched using the --remote option.

Arguments

NameDescriptionOptional
--format Format of the resulting archive: tar, zip, tar.gz, or tgz. Yes
--prefix Prepend a prefix to each filename in the archive. Yes
--output Write the archive to a file instead of stdout. Yes
tree-ish The tree or commit to produce an archive for. No

Example

git archive --format=tar.gz --prefix=project-v1.0/ HEAD > release.tar.gz
git archive --format=zip HEAD > project.zip
git archive HEAD -- src/ docs/ > partial.tar

Reference