Skip to content
LatchkeyLatchkey home

git archive: Usage, Options & Common CI Errors

git archive packages the files of a commit or tree into a tar or zip - no history, no .git.

Archive is the clean way to produce a release tarball from a tag without shipping Git metadata.

What it does

git archive writes the contents of a tree-ish (commit, tag, or tree) to a tar or zip stream, excluding the repository metadata, optionally adding a path prefix.

Common usage

Terminal
git archive --format=tar.gz -o release.tar.gz v1.2.0
git archive --format=zip --prefix=app/ HEAD -o app.zip
git archive HEAD | tar -x -C /tmp/export

Options

FlagWhat it does
--format=<tar|zip|tar.gz>Output archive format
-o / --output=<file>Write to a file instead of stdout
--prefix=<dir>/Prepend a directory to every path
--remote=<repo>Archive directly from a remote
<tree-ish>Commit, tag, or tree to export

Common errors in CI

fatal: Operation not supported by protocol (for --remote) - many hosts disable remote git archive over HTTP/SSH; clone then archive locally instead. fatal: not a valid object name means the ref does not exist in the (possibly shallow) checkout.

Using this in CI

CI checkouts are shallow and detached by default, which changes the answer this command gives you. Commands that read history, branch names, or tags need the checkout configured for it.

.github/workflows/ci.yml
- uses: actions/checkout@v4
  with:
    fetch-depth: 0   # history, tags, and git describe all need this

- run: |
    git rev-parse --is-shallow-repository   # expect false
    git rev-parse --abbrev-ref HEAD          # prints HEAD when detached

Frequently asked questions

git archive: Usage, Options & Common CI Errors?
Archive is the clean way to produce a release tarball from a tag without shipping Git metadata.
What it does?
git archive writes the contents of a tree-ish (commit, tag, or tree) to a tar or zip stream, excluding the repository metadata, optionally adding a path prefix.
Common errors in CI?
fatal: Operation not supported by protocol (for --remote) - many hosts disable remote git archive over HTTP/SSH; clone then archive locally instead. fatal: not a valid object name means the ref does not exist in the (possibly shallow) checkout.

Related guides

References

Run this faster and cheaper on Latchkey managed runners - self-healing included. Start free → 30-day trial · No credit card