{
    "content": [
        {
            "type": "text",
            "text": "# git-archive(1) (man)\n\n**Summary:** git-archive - Create an archive of files from a named tree\n\n**Synopsis:** git archive [--format=<fmt>] [--list] [--prefix=<prefix>/] [<extra>]\n[-o <file> | --output=<file>] [--worktree-attributes]\n[--remote=<repo> [--exec=<git-upload-archive>]] <tree-ish>\n[<path>...]\n\n## Flags\n\n| Flag | Long | Arg | Description |\n|------|------|-----|-------------|\n| -l | --list | — | Show all available formats. |\n| -v | --verbose | — | Report progress to stderr. --prefix=<prefix>/ Prepend <prefix>/ to each filename in the archive. -o <file>, --output=<fi |\n| — | --worktree-attributes | — | Look for attributes in .gitattributes files in the working tree as well (see the section called “ATTRIBUTES”). <extra> T |\n\n## Examples\n\n- `Create a tar archive that contains the contents of the latest commit on the current`\n- `branch, and extract it in the /var/tmp/junk directory.`\n- `Create a compressed tarball for v1.4.0 release.`\n- `Same as above, but using the builtin tar.gz handling.`\n- `Same as above, but the format is inferred from the output file.`\n- `Create a compressed tarball for v1.4.0 release, but without a global extended pax header.`\n- `Put everything in the current head’s Documentation/ directory into git-1.4.0-docs.zip,`\n- `with the prefix git-docs/.`\n- `Create a Zip archive that contains the contents of the latest commit on the current`\n- `branch. Note that the output format is inferred by the extension of the output file.`\n- `Configure a \"tar.xz\" format for making LZMA-compressed tarfiles. You can use it`\n- `specifying --format=tar.xz, or by creating an output file like -o foo.tar.xz.`\n\n## See Also\n\n- gitattributes(5)\n\n## Section Outline\n\n- **NAME** (2 lines)\n- **SYNOPSIS** (6 lines)\n- **DESCRIPTION** (11 lines)\n- **OPTIONS** (5 lines) — 3 subsections\n  - -l, --list (2 lines)\n  - -v, --verbose (13 lines)\n  - --worktree-attributes (22 lines)\n- **BACKEND EXTRA OPTIONS** (1 lines) — 2 subsections\n  - zip (5 lines)\n  - tar (5 lines)\n- **CONFIGURATION** (20 lines)\n- **ATTRIBUTES** (15 lines)\n- **EXAMPLES** (1 lines) — 8 subsections\n  - git archive --format=tar --prefix=junk/ HEAD | (cd /var/tmp/ (3 lines)\n  - git archive --format=tar --prefix=git-1.4.0/ v1.4.0 | gzip > (2 lines)\n  - git archive --format=tar.gz --prefix=git-1.4.0/ v1.4.0 >git- (2 lines)\n  - git archive --prefix=git-1.4.0/ -o git-1.4.0.tar.gz v1.4.0 (2 lines)\n  - git archive --format=tar --prefix=git-1.4.0/ v1.4.0^{tree} | (2 lines)\n  - git archive --format=zip --prefix=git-docs/ HEAD:Documentati (3 lines)\n  - git archive -o latest.zip HEAD (3 lines)\n  - git config tar.tar.xz.command \"xz -c\" (3 lines)\n- **SEE ALSO** (2 lines)\n- **GIT** (5 lines)\n\n## Full Content\n\n### NAME\n\ngit-archive - Create an archive of files from a named tree\n\n### SYNOPSIS\n\ngit archive [--format=<fmt>] [--list] [--prefix=<prefix>/] [<extra>]\n[-o <file> | --output=<file>] [--worktree-attributes]\n[--remote=<repo> [--exec=<git-upload-archive>]] <tree-ish>\n[<path>...]\n\n### DESCRIPTION\n\nCreates an archive of the specified format containing the tree structure for the named tree,\nand writes it out to the standard output. If <prefix> is specified it is prepended to the\nfilenames in the archive.\n\ngit archive behaves differently when given a tree ID versus when given a commit ID or tag ID.\nIn the first case the current time is used as the modification time of each file in the\narchive. In the latter case the commit time as recorded in the referenced commit object is\nused instead. Additionally the commit ID is stored in a global extended pax header if the tar\nformat is used; it can be extracted using git get-tar-commit-id. In ZIP files it is stored as\na file comment.\n\n### OPTIONS\n\n--format=<fmt>\nFormat of the resulting archive: tar or zip. If this option is not given, and the output\nfile is specified, the format is inferred from the filename if possible (e.g. writing to\n\"foo.zip\" makes the output to be in the zip format). Otherwise the output format is tar.\n\n#### -l, --list\n\nShow all available formats.\n\n#### -v, --verbose\n\nReport progress to stderr.\n\n--prefix=<prefix>/\nPrepend <prefix>/ to each filename in the archive.\n\n-o <file>, --output=<file>\nWrite the archive to <file> instead of stdout.\n\n--add-file=<file>\nAdd a non-tracked file to the archive. Can be repeated to add multiple files. The path of\nthe file in the archive is built by concatenating the value for --prefix (if any) and the\nbasename of <file>.\n\n#### --worktree-attributes\n\nLook for attributes in .gitattributes files in the working tree as well (see the section\ncalled “ATTRIBUTES”).\n\n<extra>\nThis can be any options that the archiver backend understands. See next section.\n\n--remote=<repo>\nInstead of making a tar archive from the local repository, retrieve a tar archive from a\nremote repository. Note that the remote repository may place restrictions on which sha1\nexpressions may be allowed in <tree-ish>. See git-upload-archive(1) for details.\n\n--exec=<git-upload-archive>\nUsed with --remote to specify the path to the git-upload-archive on the remote side.\n\n<tree-ish>\nThe tree or commit to produce an archive for.\n\n<path>\nWithout an optional path parameter, all files and subdirectories of the current working\ndirectory are included in the archive. If one or more paths are specified, only these are\nincluded.\n\n### BACKEND EXTRA OPTIONS\n\n#### zip\n\n-<digit>\nSpecify compression level. Larger values allow the command to spend more time to compress\nto smaller size. Supported values are from -0 (store-only) to -9 (best ratio). Default is\n-6 if not given.\n\n#### tar\n\n-<number>\nSpecify compression level. The value will be passed to the compression command configured\nin tar.<format>.command. See manual page of the configured command for the list of\nsupported levels and the default level if this option isn’t specified.\n\n### CONFIGURATION\n\ntar.umask\nThis variable can be used to restrict the permission bits of tar archive entries. The\ndefault is 0002, which turns off the world write bit. The special value \"user\" indicates\nthat the archiving user’s umask will be used instead. See umask(2) for details. If\n--remote is used then only the configuration of the remote repository takes effect.\n\ntar.<format>.command\nThis variable specifies a shell command through which the tar output generated by git\narchive should be piped. The command is executed using the shell with the generated tar\nfile on its standard input, and should produce the final output on its standard output.\nAny compression-level options will be passed to the command (e.g., \"-9\"). An output file\nwith the same extension as <format> will be use this format if no other format is given.\n\nThe \"tar.gz\" and \"tgz\" formats are defined automatically and default to gzip -cn. You may\noverride them with custom commands.\n\ntar.<format>.remote\nIf true, enable <format> for use by remote clients via git-upload-archive(1). Defaults to\nfalse for user-defined formats, but true for the \"tar.gz\" and \"tgz\" formats.\n\n### ATTRIBUTES\n\nexport-ignore\nFiles and directories with the attribute export-ignore won’t be added to archive files.\nSee gitattributes(5) for details.\n\nexport-subst\nIf the attribute export-subst is set for a file then Git will expand several placeholders\nwhen adding this file to an archive. See gitattributes(5) for details.\n\nNote that attributes are by default taken from the .gitattributes files in the tree that is\nbeing archived. If you want to tweak the way the output is generated after the fact (e.g. you\ncommitted without adding an appropriate export-ignore in its .gitattributes), adjust the\nchecked out .gitattributes file as necessary and use --worktree-attributes option.\nAlternatively you can keep necessary attributes that should apply while archiving any tree in\nyour $GITDIR/info/attributes file.\n\n### EXAMPLES\n\n#### git archive --format=tar --prefix=junk/ HEAD | (cd /var/tmp/ && tar xf -)\n\nCreate a tar archive that contains the contents of the latest commit on the current\nbranch, and extract it in the /var/tmp/junk directory.\n\n#### git archive --format=tar --prefix=git-1.4.0/ v1.4.0 | gzip >git-1.4.0.tar.gz\n\nCreate a compressed tarball for v1.4.0 release.\n\n#### git archive --format=tar.gz --prefix=git-1.4.0/ v1.4.0 >git-1.4.0.tar.gz\n\nSame as above, but using the builtin tar.gz handling.\n\n#### git archive --prefix=git-1.4.0/ -o git-1.4.0.tar.gz v1.4.0\n\nSame as above, but the format is inferred from the output file.\n\n#### git archive --format=tar --prefix=git-1.4.0/ v1.4.0^{tree} | gzip >git-1.4.0.tar.gz\n\nCreate a compressed tarball for v1.4.0 release, but without a global extended pax header.\n\n#### git archive --format=zip --prefix=git-docs/ HEAD:Documentation/ > git-1.4.0-docs.zip\n\nPut everything in the current head’s Documentation/ directory into git-1.4.0-docs.zip,\nwith the prefix git-docs/.\n\n#### git archive -o latest.zip HEAD\n\nCreate a Zip archive that contains the contents of the latest commit on the current\nbranch. Note that the output format is inferred by the extension of the output file.\n\n#### git config tar.tar.xz.command \"xz -c\"\n\nConfigure a \"tar.xz\" format for making LZMA-compressed tarfiles. You can use it\nspecifying --format=tar.xz, or by creating an output file like -o foo.tar.xz.\n\n### SEE ALSO\n\ngitattributes(5)\n\n### GIT\n\nPart of the git(1) suite\n\n\n\nGit 2.34.1                                   02/26/2026                               GIT-ARCHIVE(1)\n\n"
        }
    ],
    "structuredContent": {
        "command": "git-archive",
        "section": "1",
        "mode": "man",
        "summary": "git-archive - Create an archive of files from a named tree",
        "synopsis": "git archive [--format=<fmt>] [--list] [--prefix=<prefix>/] [<extra>]\n[-o <file> | --output=<file>] [--worktree-attributes]\n[--remote=<repo> [--exec=<git-upload-archive>]] <tree-ish>\n[<path>...]",
        "flags": [
            {
                "flag": "-l",
                "long": "--list",
                "arg": null,
                "description": "Show all available formats."
            },
            {
                "flag": "-v",
                "long": "--verbose",
                "arg": null,
                "description": "Report progress to stderr. --prefix=<prefix>/ Prepend <prefix>/ to each filename in the archive. -o <file>, --output=<file> Write the archive to <file> instead of stdout. --add-file=<file> Add a non-tracked file to the archive. Can be repeated to add multiple files. The path of the file in the archive is built by concatenating the value for --prefix (if any) and the basename of <file>."
            },
            {
                "flag": "",
                "long": "--worktree-attributes",
                "arg": null,
                "description": "Look for attributes in .gitattributes files in the working tree as well (see the section called “ATTRIBUTES”). <extra> This can be any options that the archiver backend understands. See next section. --remote=<repo> Instead of making a tar archive from the local repository, retrieve a tar archive from a remote repository. Note that the remote repository may place restrictions on which sha1 expressions may be allowed in <tree-ish>. See git-upload-archive(1) for details. --exec=<git-upload-archive> Used with --remote to specify the path to the git-upload-archive on the remote side. <tree-ish> The tree or commit to produce an archive for. <path> Without an optional path parameter, all files and subdirectories of the current working directory are included in the archive. If one or more paths are specified, only these are included."
            }
        ],
        "examples": [
            "Create a tar archive that contains the contents of the latest commit on the current",
            "branch, and extract it in the /var/tmp/junk directory.",
            "Create a compressed tarball for v1.4.0 release.",
            "Same as above, but using the builtin tar.gz handling.",
            "Same as above, but the format is inferred from the output file.",
            "Create a compressed tarball for v1.4.0 release, but without a global extended pax header.",
            "Put everything in the current head’s Documentation/ directory into git-1.4.0-docs.zip,",
            "with the prefix git-docs/.",
            "Create a Zip archive that contains the contents of the latest commit on the current",
            "branch. Note that the output format is inferred by the extension of the output file.",
            "Configure a \"tar.xz\" format for making LZMA-compressed tarfiles. You can use it",
            "specifying --format=tar.xz, or by creating an output file like -o foo.tar.xz."
        ],
        "see_also": [
            {
                "name": "gitattributes",
                "section": "5",
                "url": "https://www.chedong.com/phpMan.php/man/gitattributes/5/json"
            }
        ],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 6,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 11,
                "subsections": []
            },
            {
                "name": "OPTIONS",
                "lines": 5,
                "subsections": [
                    {
                        "name": "-l, --list",
                        "lines": 2,
                        "flag": "-l",
                        "long": "--list"
                    },
                    {
                        "name": "-v, --verbose",
                        "lines": 13,
                        "flag": "-v",
                        "long": "--verbose"
                    },
                    {
                        "name": "--worktree-attributes",
                        "lines": 22,
                        "long": "--worktree-attributes"
                    }
                ]
            },
            {
                "name": "BACKEND EXTRA OPTIONS",
                "lines": 1,
                "subsections": [
                    {
                        "name": "zip",
                        "lines": 5
                    },
                    {
                        "name": "tar",
                        "lines": 5
                    }
                ]
            },
            {
                "name": "CONFIGURATION",
                "lines": 20,
                "subsections": []
            },
            {
                "name": "ATTRIBUTES",
                "lines": 15,
                "subsections": []
            },
            {
                "name": "EXAMPLES",
                "lines": 1,
                "subsections": [
                    {
                        "name": "git archive --format=tar --prefix=junk/ HEAD | (cd /var/tmp/ && tar xf -)",
                        "lines": 3
                    },
                    {
                        "name": "git archive --format=tar --prefix=git-1.4.0/ v1.4.0 | gzip >git-1.4.0.tar.gz",
                        "lines": 2
                    },
                    {
                        "name": "git archive --format=tar.gz --prefix=git-1.4.0/ v1.4.0 >git-1.4.0.tar.gz",
                        "lines": 2
                    },
                    {
                        "name": "git archive --prefix=git-1.4.0/ -o git-1.4.0.tar.gz v1.4.0",
                        "lines": 2
                    },
                    {
                        "name": "git archive --format=tar --prefix=git-1.4.0/ v1.4.0^{tree} | gzip >git-1.4.0.tar.gz",
                        "lines": 2
                    },
                    {
                        "name": "git archive --format=zip --prefix=git-docs/ HEAD:Documentation/ > git-1.4.0-docs.zip",
                        "lines": 3
                    },
                    {
                        "name": "git archive -o latest.zip HEAD",
                        "lines": 3
                    },
                    {
                        "name": "git config tar.tar.xz.command \"xz -c\"",
                        "lines": 3
                    }
                ]
            },
            {
                "name": "SEE ALSO",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "GIT",
                "lines": 5,
                "subsections": []
            }
        ]
    }
}