# git archive: Usage, Options & Common CI Errors

> git archive exports a tree as a tar or zip without the .git directory. Reference for --format, --prefix, --output, and remote-archive errors in CI.

Source: https://latchkey.dev/learn/command-reference/git-archive  
Updated: 2026-06-25

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

| Flag | What 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
```

> `git rev-parse --abbrev-ref HEAD` returns the literal string `HEAD` on a detached checkout rather than a branch name. On GitHub Actions read `github.ref_name` instead; the git command cannot know what it was checked out for.

## FAQ

### 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.

---

Latchkey runs CI/CD that repairs its own failures. Agent entry points: https://latchkey.dev/agent.txt, https://latchkey.dev/openapi.json, https://latchkey.dev/llms.txt
