LinuxCommandLibrary

git-archive

Create archives of repository files without version control metadata

TLDR

Create tar archive of HEAD
$ git archive HEAD -o [archive.tar]
copy
Create zip archive
$ git archive --format=zip HEAD -o [archive.zip]
copy
Archive specific commit
$ git archive [commit] -o [archive.tar]
copy
Archive specific directory
$ git archive HEAD [path/to/dir] -o [archive.tar]
copy
Archive with prefix
$ git archive --prefix=[project/] HEAD -o [archive.tar]
copy
Create and compress
$ git archive HEAD | gzip > [archive.tar.gz]
copy

SYNOPSIS

git archive [options] tree-ish [path...]

DESCRIPTION

git archive creates archive files (tar, zip) containing repository content at a specific commit or branch without including the .git directory and other version control metadata. This is essential for creating clean distribution packages and release artifacts.
The command supports multiple archive formats including tar, zip, and tar.gz through pipes. Archives can be created from any tree-ish reference (commit, branch, tag) and can include specific subdirectories or use path filtering to include only desired files.
Prefix support allows prepending a directory structure to all archived files, useful for creating archives that extract into a specific folder. Remote repository archives can be created without local checkout using the --remote option, though this requires server support.

PARAMETERS

--format format

Archive format (tar, zip, tar.gz).
-o, --output file
Output file.
--prefix prefix
Prepend prefix to paths.
--remote repo
Archive from remote.
-l, --list
List available formats.

SEE ALSO

git-bundle(1), tar(1)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard