{
    "mode": "man",
    "parameter": "GIT-ARCHIVE",
    "section": "1",
    "url": "https://www.chedong.com/phpMan.php/man/GIT-ARCHIVE/1/json",
    "generated": "2026-10-21T16:26:13Z",
    "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>...]",
    "sections": {
        "NAME": {
            "content": "git-archive - Create an archive of files from a named tree\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "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",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "Creates 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 as opposed to a commit ID or tag ID.\nWhen a tree ID is provided, the current time is used as the modification time of each file in\nthe archive. On the other hand, when a commit ID or tag ID is provided, the commit time as\nrecorded in the referenced commit object is used instead. Additionally the commit ID is\nstored in a global extended pax header if the tar format is used; it can be extracted using\ngit get-tar-commit-id. In ZIP files it is stored as a file comment.\n",
            "subsections": []
        },
        "OPTIONS": {
            "content": "--format=<fmt>\nFormat of the resulting archive. Possible values are tar, zip, tar.gz, tgz, and any\nformat defined using the configuration option tar.<format>.command. If --format is not\ngiven, and the output file is specified, the format is inferred from the filename if\npossible (e.g. writing to foo.zip makes the output to be in the zip format). Otherwise\nthe output format is tar.\n",
            "subsections": [
                {
                    "name": "-l, --list",
                    "content": "Show all available formats.\n",
                    "flag": "-l",
                    "long": "--list"
                },
                {
                    "name": "-v, --verbose",
                    "content": "Report progress to stderr.\n\n--prefix=<prefix>/\nPrepend <prefix>/ to paths in the archive. Can be repeated; its rightmost value is used\nfor all tracked files. See below which value gets used by --add-file and\n--add-virtual-file.\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 of the last --prefix option\n(if any) before this --add-file and the basename of <file>.\n\n--add-virtual-file=<path>:<content>\nAdd the specified contents to the archive. Can be repeated to add multiple files. The\npath of the file in the archive is built by concatenating the value of the last --prefix\noption (if any) before this --add-virtual-file and <path>.\n\nThe <path> argument can start and end with a literal double-quote character; the\ncontained file name is interpreted as a C-style string, i.e. the backslash is interpreted\nas escape character. The path must be quoted if it contains a colon, to avoid the colon\nfrom being misinterpreted as the separator between the path and the contents, or if the\npath begins or ends with a double-quote character.\n\nThe file mode is limited to a regular file, and the option may be subject to\nplatform-dependent command-line limits. For non-trivial cases, write an untracked file\nand use --add-file instead.\n",
                    "flag": "-v",
                    "long": "--verbose"
                },
                {
                    "name": "--worktree-attributes",
                    "content": "Look for attributes in .gitattributes files in the working tree as well (see the section\ncalled “ATTRIBUTES”).\n\n--mtime=<time>\nSet modification time of archive entries. Without this option the committer time is used\nif <tree-ish> is a commit or tag, and the current time if it is a tree.\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",
                    "long": "--worktree-attributes"
                }
            ]
        },
        "BACKEND EXTRA OPTIONS": {
            "content": "",
            "subsections": [
                {
                    "name": "zip",
                    "content": "-<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"
                },
                {
                    "name": "tar",
                    "content": "-<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"
                }
            ]
        },
        "CONFIGURATION": {
            "content": "tar.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).\n\nThe tar.gz and tgz formats are defined automatically and use the magic command git\narchive gzip by default, which invokes an internal implementation of gzip.\n\ntar.<format>.remote\nIf true, enable the format for use by remote clients via git-upload-archive(1). Defaults\nto false for user-defined formats, but true for the tar.gz and tgz formats.\n",
            "subsections": []
        },
        "ATTRIBUTES": {
            "content": "export-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",
            "subsections": []
        },
        "EXAMPLES": {
            "content": "",
            "subsections": [
                {
                    "name": "git archive --format=tar --prefix=junk/ HEAD | (cd /var/tmp/ && tar xf -)",
                    "content": "Create 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"
                },
                {
                    "name": "git archive --format=tar --prefix=git-1.4.0/ v1.4.0 | gzip >git-1.4.0.tar.gz",
                    "content": "Create a compressed tarball for v1.4.0 release.\n"
                },
                {
                    "name": "git archive --format=tar.gz --prefix=git-1.4.0/ v1.4.0 >git-1.4.0.tar.gz",
                    "content": "Same as above, but using the builtin tar.gz handling.\n"
                },
                {
                    "name": "git archive --prefix=git-1.4.0/ -o git-1.4.0.tar.gz v1.4.0",
                    "content": "Same as above, but the format is inferred from the output file.\n"
                },
                {
                    "name": "git archive --format=tar --prefix=git-1.4.0/ v1.4.0^{tree} | gzip >git-1.4.0.tar.gz",
                    "content": "Create a compressed tarball for v1.4.0 release, but without a global extended pax header.\n"
                },
                {
                    "name": "git archive --format=zip --prefix=git-docs/ HEAD:Documentation/ > git-1.4.0-docs.zip",
                    "content": "Put everything in the current head’s Documentation/ directory into git-1.4.0-docs.zip,\nwith the prefix git-docs/.\n"
                },
                {
                    "name": "git archive -o latest.zip HEAD",
                    "content": "Create 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"
                },
                {
                    "name": "git archive -o latest.tar --prefix=build/ --add-file=configure --prefix= HEAD",
                    "content": "Creates a tar archive that contains the contents of the latest commit on the current\nbranch with no prefix and the untracked file configure with the prefix build/.\n"
                },
                {
                    "name": "git config tar.tar.xz.command \"xz -c\"",
                    "content": "Configure 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"
                }
            ]
        },
        "SEE ALSO": {
            "content": "gitattributes(5)\n",
            "subsections": []
        },
        "GIT": {
            "content": "Part of the git(1) suite\n\nGit 2.43.0                                   07/02/2025                               GIT-ARCHIVE(1)",
            "subsections": []
        }
    },
    "summary": "git-archive - Create an archive of files from a named tree",
    "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 paths in the archive. Can be repeated; its rightmost value is used for all tracked files. See below which value gets used by --add-file and --add-virtual-file. -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 of the last --prefix option (if any) before this --add-file and the basename of <file>. --add-virtual-file=<path>:<content> Add the specified contents to the archive. Can be repeated to add multiple files. The path of the file in the archive is built by concatenating the value of the last --prefix option (if any) before this --add-virtual-file and <path>. The <path> argument can start and end with a literal double-quote character; the contained file name is interpreted as a C-style string, i.e. the backslash is interpreted as escape character. The path must be quoted if it contains a colon, to avoid the colon from being misinterpreted as the separator between the path and the contents, or if the path begins or ends with a double-quote character. The file mode is limited to a regular file, and the option may be subject to platform-dependent command-line limits. For non-trivial cases, write an untracked file and use --add-file instead."
        },
        {
            "flag": "",
            "long": "--worktree-attributes",
            "arg": null,
            "description": "Look for attributes in .gitattributes files in the working tree as well (see the section called “ATTRIBUTES”). --mtime=<time> Set modification time of archive entries. Without this option the committer time is used if <tree-ish> is a commit or tag, and the current time if it is a tree. <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.",
        "Creates a tar archive that contains the contents of the latest commit on the current",
        "branch with no prefix and the untracked file configure with the prefix build/.",
        "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"
        }
    ],
    "tldr": {
        "source": "official",
        "description": "Create an archive of files from a tree.",
        "examples": [
            {
                "description": "Create a `.tar` archive from the contents of the current `HEAD` and print it to `stdout`",
                "command": "git archive {{-v|--verbose}} HEAD"
            },
            {
                "description": "Use the Zip format and report progress verbosely",
                "command": "git archive {{-v|--verbose}} --format zip HEAD"
            },
            {
                "description": "Output the Zip archive to a specific file",
                "command": "git archive {{-v|--verbose}} {{-o|--output}} {{path/to/file.zip}} HEAD"
            },
            {
                "description": "Create a `.tar` archive from the contents of the latest commit of a specific branch",
                "command": "git archive {{-o|--output}} {{path/to/file.tar}} {{branch_name}}"
            },
            {
                "description": "Use the contents of a specific directory",
                "command": "git archive {{-o|--output}} {{path/to/file.tar}} HEAD:{{path/to/directory}}"
            },
            {
                "description": "Prepend a path to each file to archive it inside a specific directory",
                "command": "git archive {{-o|--output}} {{path/to/file.tar}} --prefix {{path/to/prepend}}/ HEAD"
            }
        ]
    }
}