Packaging source from Git is different from copying a working tree, because a release archive should contain the tracked files from one chosen revision and leave repository metadata behind. git archive creates that handoff artifact from a commit, tag, branch, or tree without including the .git directory.
The command reads a named tree and writes an archive in a supported format such as tar, zip, tar.gz, or tgz. A top-level prefix such as project/ keeps extraction organized, and a specific revision such as HEAD or a release tag makes the packaged file repeatable.
Only committed tracked files are included unless extra archive options add files explicitly. Committed .gitattributes rules such as export-ignore can remove files from the archive, so list the archive before sharing it and avoid unsafe prefixes such as absolute paths or ../.
$ git rev-parse HEAD
3608feb175138849f6e2b6fcb92a72ece92cc29c
Replace HEAD with a release tag, branch name, or commit ID when the archive must come from a specific point in history.
$ git archive --format=tar --prefix=project/ --output=project.tar HEAD
Use a trailing slash in --prefix=project/ so extracted files land under one directory instead of directly in the destination folder.
$ tar tf project.tar project/ project/README.md project/src/ project/src/app.py
The listing should show the expected tracked files under the prefix. The .git directory and untracked working-tree files should be absent.
$ git get-tar-commit-id < project.tar 3608feb175138849f6e2b6fcb92a72ece92cc29c
The value should match the revision resolved before the archive was created. For zip output, Git stores the commit ID as a file comment instead of a tar header.