git-upload-archive - Linux
Overview
git-upload-archive
prepares an archive of the specified tree or commit that can be distributed to others. It compresses the data, and creates a file named archive.tar.gz
, in the current directory.
Syntax
git upload-archive [<options>] <tree-ish>
Options/Flags
- -f,–format=
: Format of the archive. Defaults to tar
. - -C,–directory=
: Directory from which to create archive. - -q,–quiet: Suppress warnings about missing HEAD.
- -u,–upload-pack=
: Path to custom upload-pack program.
Examples
Create an archive of the current HEAD tree:
git upload-archive HEAD
Create an archive of a specific commit:
git upload-archive 2139431
Create an archive of a specific directory:
git upload-archive -C docs HEAD
Create an archive in zip format:
git upload-archive -f zip HEAD
Common Issues
"Missing HEAD" warning: Occurs when using --quiet
while outside a repository. Ensure you are in a Git repository before running the command.
Upload-pack not found: Some older systems may not have upload-pack
in the default path. Specify the path to upload-pack
using --upload-pack
.
Integration
git-upload-archive
can be used in conjunction with other Git commands for advanced tasks, such as:
git fetch origin master | git upload-archive --stdin
This fetches the latest master branch from a remote repository and immediately creates an archive from it.