Progress:
TIER 1 · MODULE 35· Basics

git archive

Like a .tar.gz of any commit, no .git inside.

🎯 What & why

Export a tree-ish (commit, tag, branch) as a tar or zip archive. Like tar -cf but pulled from the object DB, with no .git/ inside.

🧠 Mental model

Archive walks the tree object at the chosen ref, streams each blob through the configured filters (text, export-subst, etc.), and writes a tar/zip stream. Nothing in the working tree or index matters — it's a pure object-DB read.

🛠️ Synopsis

git archive [--format=<fmt>] [--list] [--prefix=<prefix>/] [<extra>]
            [-o | --output=<file>] [--worktree-attributes]
            [--remote=<repo> [--exec=<git-upload-archive>]] <tree-ish>
            [<path>...]

🎚️ Switches & options

FlagWhat it does
--format=tar|zip|tar.gzOutput format.
--prefix=<dir>/Prepend a directory inside the archive.
-o <file>Write to file instead of stdout.
--remote=<repo>Archive a remote repo without cloning (uses upload-archive).

💡 Use cases

🧪 Examples

Archive HEAD as a tar.
$ git archive --format=tar HEAD > release.tar
Tarball with prefix dir.
$ git archive --format=tar.gz --prefix=proj-1.2/ v1.2 -o proj-1.2.tar.gz
Archive only one directory.
$ git archive HEAD docs/ > docs.tar

🎓 Recommendations

🪤 Common pitfalls

🔗 Related modules

📝 Quiz

Hit each option, then Check answers. Score is recorded; Next is always open.