git archive --remote=<repo> <commit>
This command generates an archive of a specific state of a remote Git repository, which is useful when you need the files for a particular commit without doing a full clone or checkout locally.
It works by asking the remote Git server to run git archive on your behalf using --remote=<repo>, where <repo> is a remote URL (for example an SSH URL like ssh://user@host/path/to/repo.git or a standard Git URL), and <commit> is any valid commit reference on that remote such as a branch name, tag, or commit hash; the remote then streams back a tar archive of the tree at that commit, which you can redirect to a file or pipe into other tools. The --remote flag can also be written as --remote <repo> (space instead of =) but it behaves the same way, and <commit> can be something like main, v1.0.0, or a1b2c3d depending on what you want to archive.
You can extend this command with options like -o/--output to save directly to a file (for example -o source.tar), --format=zip to change the archive format to zip instead of the default tar, or --prefix=src/ to put all archived files under a src/ directory inside the archive; you can also pass path filters after <commit> (e.g. -- README.md src/) to archive only part of the tree.
Closely related variants include running the same command locally without --remote when you already have the repository cloned (for example git archive <commit> -o source.tar), or using git archive --remote=<repo> HEAD to always grab the latest version of a default branch; you might also combine this with tools like tar -xvf - by piping the output (e.g. git archive --remote=<repo> <commit> | tar -xvf -) to extract files directly without saving the archive file first.
Examples:
git archive --remote=ssh://git@example.com/projects/my-repo.git maingit archive --remote=git@example.com:org/app.git v1.2.3