LinuxCommandLibrary

git-archive-file

Create an archive from a Git repository

TLDR

Pack the currently checked out commit into a Zip archive

$ git archive-file
copy

SYNOPSIS

git archive-file [--verbose] [--prefix=/] [--format=] [--remote=] [:]

PARAMETERS

--verbose
    Enable verbose operation. Prints information about the files being archived.

--prefix=/
    Prefix all paths in the archive with the given prefix.

--format=
    The format of the archive. Valid formats include 'tar', 'zip', etc. If not specified, git attempts to infer from the output file's extension.

--remote=
    Retrieve the archive from a remote repository.


    The name of the archive file to create.

[:]
    The tree-ish (commit, tag, or branch) to archive. Optionally, a path within the repository can be specified.

DESCRIPTION

The git-archive-file command is a plumbing command used to create an archive file from a specified git repository. It takes the contents of a specified tree-ish (a commit, tag, or branch) and packages them into an archive in various formats, such as tar or zip. This command is primarily intended for scripted usage, providing a simple and efficient way to export a repository's contents for distribution or backup purposes.

Unlike `git archive`, `git-archive-file` writes directly to a specified file rather than stdout, making it more suitable for automation workflows. It offers control over archive format and inclusion/exclusion of files using standard gitignore patterns. The command is typically used for automating releases or creating backups of specific repository states, providing a clean and consistent way to manage repository snapshots.

CAVEATS

The archive format is determined either from the `--format` option or the file extension of . Ensure the specified format is supported by your system.

EXAMPLE USAGE

To create a tar archive of the 'main' branch named 'my_archive.tar':
git archive-file my_archive.tar main

To create a zip archive of the 'develop' branch with a prefix 'project/' named 'release.zip':
git archive-file --format=zip --prefix=project/ release.zip develop

SEE ALSO

git archive(1), git checkout(1)

Copied to clipboard