git archive --format=zip

Create a ZIP archive of the repository’s files at a given commit or branch.

This command is useful when you want to export your project’s tracked files as a clean, ready-to-share ZIP file without any of the .git history or metadata.

It tells Git to generate an archive (git archive) and uses the --format=zip flag to specify that the output should be in ZIP format instead of the default tar; by itself, this command expects you to also provide a tree-ish (like main, v1.0.0, or a commit hash) and usually an output target via > file.zip or -o file.zip, so for example git archive --format=zip main > project.zip would write the ZIP to project.zip, including only tracked files as they exist on main (no untracked or ignored files).

You can customize this further with flags like --output=<file> (short form -o <file>) to avoid shell redirection, e.g. git archive --format=zip -o project.zip main, or add --prefix=<dir>/ to wrap all archived files inside a top-level directory, e.g. --prefix=project/ to make the ZIP unpack into a project/ folder; you can also limit the archive to a specific subdirectory or paths by listing them after the tree-ish, such as git archive --format=zip -o src-only.zip main src/. Related commands include using --format=tar (or omitting --format entirely, since tar is the default) to create tar archives instead of ZIPs, and pairing with git ls-tree to inspect which paths are available before archiving them, or using git bundle when you need to export repository history instead of just a snapshot of the files.

Examples:

  • git archive --format=zip -o project.zip main
  • git archive --format=zip -o release-1.0.zip v1.0.0
  • git archive --format=zip --prefix=project/ -o project-src.zip main src/
Manual page
git archive
Related commands

Welcome to GitExamples!

Sign in to enable bookmarking, reminders, progress-tracking and more...