git-archive-file
Create an archive from a Git repository
TLDR
Pack the currently checked out commit into a Zip archive
SYNOPSIS
git-archive-file [options...] <file> [<ref>] <output-archive>
PARAMETERS
--format tar|zip
Set archive format (default: tar).
--prefix PREFIX/
Prepend PREFIX/ to archived pathnames.
--output -
Write archive to stdout instead of file.
--worktree-attrs
Include worktree attributes in archive.
-v, --verbose
Enable verbose output during archiving.
--remote repo
Archive from remote repository.
DESCRIPTION
git-archive-file is a lightweight utility script, not part of core Git, designed to create an archive of a single file from a Git repository at a specific ref (commit, tag, or branch). It wraps git archive functionality but simplifies usage for individual files, automatically handling paths, prefixes, and output formats like tar or zip.
Ideal for distributing versioned assets, configs, or scripts without the full repo. Specify the file path relative to the repo root, an optional ref (defaults to HEAD), and output archive name. It exports the file preserving Git attributes and timestamps from the given ref.
Common use: package a file like config.yaml at tag v2.1 into config-v2.1.tar.gz. Supports streaming to stdout for piping. Requires Git installed; script often sourced from GitHub repos or custom installs.
CAVEATS
Not a standard Git command; must install script separately (e.g., from GitHub). Fails if file not tracked at ref. Limited to single file; use git archive for multiples.
EXAMPLE USAGE
git-archive-file src/main.py v1.2.3 main-v1.2.3.tar.gz
git-archive-file --format=zip --prefix=docs/ README.md HEAD README.zip
HISTORY
Emerged as community script ~2012 on GitHub for simplifying single-file exports. Evolved with Git archive features; various forks exist, often in Perl/Python.
SEE ALSO
git-archive(1), tar(1), zip(1)


