Skip to main content
The following functions can be loaded from @bazel_tools//tools/build_defs/repo:git.bzl. // Generated with Stardoc: http://skydoc.bazel.build Rules for cloning external git repositories.

git_repository

load("@bazel//tools/build_defs/repo:git.bzl", "git_repository")

git_repository(<a href="#git_repository-name">name</a>, <a href="#git_repository-branch">branch</a>, <a href="#git_repository-build_file">build_file</a>, <a href="#git_repository-build_file_content">build_file_content</a>, <a href="#git_repository-commit">commit</a>, <a href="#git_repository-init_submodules">init_submodules</a>, <a href="#git_repository-patch_args">patch_args</a>,
               <a href="#git_repository-patch_cmds">patch_cmds</a>, <a href="#git_repository-patch_cmds_win">patch_cmds_win</a>, <a href="#git_repository-patch_strip">patch_strip</a>, <a href="#git_repository-patch_tool">patch_tool</a>, <a href="#git_repository-patches">patches</a>,
               <a href="#git_repository-recursive_init_submodules">recursive_init_submodules</a>, <a href="#git_repository-remote">remote</a>, <a href="#git_repository-remote_module_file_integrity">remote_module_file_integrity</a>,
               <a href="#git_repository-remote_module_file_urls">remote_module_file_urls</a>, <a href="#git_repository-repo_mapping">repo_mapping</a>, <a href="#git_repository-shallow_since">shallow_since</a>, <a href="#git_repository-sparse_checkout_file">sparse_checkout_file</a>,
               <a href="#git_repository-sparse_checkout_patterns">sparse_checkout_patterns</a>, <a href="#git_repository-strip_prefix">strip_prefix</a>, <a href="#git_repository-tag">tag</a>, <a href="#git_repository-verbose">verbose</a>, <a href="#git_repository-workspace_file">workspace_file</a>,
               <a href="#git_repository-workspace_file_content">workspace_file_content</a>)
Clone an external git repository. Clones a Git repository, checks out the specified tag, or commit, and makes its targets available for binding. Also determine the id of the commit actually checked out and its date, and return a dict with parameters that provide a reproducible version of this rule (which a tag not necessarily is). Bazel will first try to perform a shallow fetch of only the specified commit. If that fails (usually due to missing server support), it will fall back to a full fetch of the repository. Prefer http_archive to git_repository. The reasons are:
  • Git repository rules depend on system git(1) whereas the HTTP downloader is built into Bazel and has no system dependencies.
  • http_archive supports a list of urls as mirrors, and git_repository supports only a single remote.
  • http_archive works with the repository cache, but not git_repository. See #5116 for more information.
ATTRIBUTES
nameName; required

A unique name for this repository.

branchString; optional

branch in the remote repository to checked out. Precisely one of branch, tag, or commit must be specified.

build_fileLabel; optional

The file to use as the BUILD file for this repository. This attribute is an absolute label (use ’@//’ for the main repo). The file does not need to be named BUILD, but can be (something like BUILD.new-repo-name may work well for distinguishing it from the repository’s actual BUILD files).

build_file_contentString; optional

The content for the BUILD file for this repository.

commitString; optional

specific commit to be checked out. Precisely one of branch, tag, or commit must be specified.

init_submodulesBoolean; optional

Whether to clone submodules in the repository.

patch_argsList of strings; optional

The arguments given to the patch tool. Defaults to -p0 (see the patch_strip attribute), however -p1 will usually be needed for patches generated by git. If multiple -p arguments are specified, the last one will take effect.If arguments other than -p are specified, Bazel will fall back to use patch command line tool instead of the Bazel-native patch implementation. When falling back to patch command line tool and patch_tool attribute is not specified, patch will be used.

patch_cmdsList of strings; optional

Sequence of Bash commands to be applied on Linux/Macos after patches are applied.

patch_cmds_winList of strings; optional

Sequence of Powershell commands to be applied on Windows after patches are applied. If this attribute is not set, patch_cmds will be executed on Windows, which requires Bash binary to exist.

patch_stripInteger; optional

When set to N, this is equivalent to inserting -pN to the beginning of patch_args.

patch_toolString; optional

The patch(1) utility to use. If this is specified, Bazel will use the specified patch tool instead of the Bazel-native patch implementation.

patchesList of labels; optional

A list of files that are to be applied as patches after extracting the archive. By default, it uses the Bazel-native patch implementation which doesn’t support fuzz match and binary patch, but Bazel will fall back to use patch command line tool if patch_tool attribute is specified or there are arguments other than -p in patch_args attribute.

recursive_init_submodulesBoolean; optional

Whether to clone submodules recursively in the repository.

remoteString; required

The URI of the remote Git repository

remote_module_file_integrityString; optional

For internal use only.

remote_module_file_urlsList of strings; optional

For internal use only.

repo_mappingDictionary: String -> String; optional

In WORKSPACE context only: a dictionary from local repository name to global repository name. This allows controls over workspace dependency resolution for dependencies of this repository.For example, an entry "@foo": "@bar" declares that, for any time this repository depends on @foo (such as a dependency on @foo//some:target, it should actually resolve that dependency within globally-declared @bar (@bar//some:target).This attribute is not supported in MODULE.bazel context (when invoking a repository rule inside a module extension’s implementation function).

shallow_sinceString; optional

an optional date, not after the specified commit; the argument is not allowed if a tag or branch is specified (which can always be cloned with —depth=1). Setting such a date close to the specified commit may allow for a shallow clone of the repository even if the server does not support shallow fetches of arbitrary commits. Due to bugs in git’s —shallow-since implementation, using this attribute is not recommended as it may result in fetch failures.

sparse_checkout_fileLabel; optional

File containing .gitignore-style patterns for a sparse checkout of files in this repository. Either sparse_checkout_patterns or sparse_checkout_file may be specified, or neither, but not both.

sparse_checkout_patternsList of strings; optional

Sequence of patterns for a sparse checkout of files in this repository.

strip_prefixString; optional

A directory prefix to strip from the extracted files.

tagString; optional

tag in the remote repository to checked out. Precisely one of branch, tag, or commit must be specified.

verboseBoolean; optional
workspace_fileLabel; optional

No-op attribute; do not use.

workspace_file_contentString; optional

No-op attribute; do not use.

new_git_repository

load("@bazel//tools/build_defs/repo:git.bzl", "new_git_repository")

new_git_repository(<a href="#new_git_repository-name">name</a>, <a href="#new_git_repository-branch">branch</a>, <a href="#new_git_repository-build_file">build_file</a>, <a href="#new_git_repository-build_file_content">build_file_content</a>, <a href="#new_git_repository-commit">commit</a>, <a href="#new_git_repository-init_submodules">init_submodules</a>,
                   <a href="#new_git_repository-patch_args">patch_args</a>, <a href="#new_git_repository-patch_cmds">patch_cmds</a>, <a href="#new_git_repository-patch_cmds_win">patch_cmds_win</a>, <a href="#new_git_repository-patch_strip">patch_strip</a>, <a href="#new_git_repository-patch_tool">patch_tool</a>, <a href="#new_git_repository-patches">patches</a>,
                   <a href="#new_git_repository-recursive_init_submodules">recursive_init_submodules</a>, <a href="#new_git_repository-remote">remote</a>, <a href="#new_git_repository-remote_module_file_integrity">remote_module_file_integrity</a>,
                   <a href="#new_git_repository-remote_module_file_urls">remote_module_file_urls</a>, <a href="#new_git_repository-repo_mapping">repo_mapping</a>, <a href="#new_git_repository-shallow_since">shallow_since</a>, <a href="#new_git_repository-sparse_checkout_file">sparse_checkout_file</a>,
                   <a href="#new_git_repository-sparse_checkout_patterns">sparse_checkout_patterns</a>, <a href="#new_git_repository-strip_prefix">strip_prefix</a>, <a href="#new_git_repository-tag">tag</a>, <a href="#new_git_repository-verbose">verbose</a>, <a href="#new_git_repository-workspace_file">workspace_file</a>,
                   <a href="#new_git_repository-workspace_file_content">workspace_file_content</a>)
Clone an external git repository. Clones a Git repository, checks out the specified tag, or commit, and makes its targets available for binding. Also determine the id of the commit actually checked out and its date, and return a dict with parameters that provide a reproducible version of this rule (which a tag not necessarily is). Bazel will first try to perform a shallow fetch of only the specified commit. If that fails (usually due to missing server support), it will fall back to a full fetch of the repository. Prefer http_archive to git_repository. The reasons are:
  • Git repository rules depend on system git(1) whereas the HTTP downloader is built into Bazel and has no system dependencies.
  • http_archive supports a list of urls as mirrors, and git_repository supports only a single remote.
  • http_archive works with the repository cache, but not git_repository. See #5116 for more information.
ATTRIBUTES
nameName; required

A unique name for this repository.

branchString; optional

branch in the remote repository to checked out. Precisely one of branch, tag, or commit must be specified.

build_fileLabel; optional

The file to use as the BUILD file for this repository. This attribute is an absolute label (use ’@//’ for the main repo). The file does not need to be named BUILD, but can be (something like BUILD.new-repo-name may work well for distinguishing it from the repository’s actual BUILD files).

build_file_contentString; optional

The content for the BUILD file for this repository.

commitString; optional

specific commit to be checked out. Precisely one of branch, tag, or commit must be specified.

init_submodulesBoolean; optional

Whether to clone submodules in the repository.

patch_argsList of strings; optional

The arguments given to the patch tool. Defaults to -p0 (see the patch_strip attribute), however -p1 will usually be needed for patches generated by git. If multiple -p arguments are specified, the last one will take effect.If arguments other than -p are specified, Bazel will fall back to use patch command line tool instead of the Bazel-native patch implementation. When falling back to patch command line tool and patch_tool attribute is not specified, patch will be used.

patch_cmdsList of strings; optional

Sequence of Bash commands to be applied on Linux/Macos after patches are applied.

patch_cmds_winList of strings; optional

Sequence of Powershell commands to be applied on Windows after patches are applied. If this attribute is not set, patch_cmds will be executed on Windows, which requires Bash binary to exist.

patch_stripInteger; optional

When set to N, this is equivalent to inserting -pN to the beginning of patch_args.

patch_toolString; optional

The patch(1) utility to use. If this is specified, Bazel will use the specified patch tool instead of the Bazel-native patch implementation.

patchesList of labels; optional

A list of files that are to be applied as patches after extracting the archive. By default, it uses the Bazel-native patch implementation which doesn’t support fuzz match and binary patch, but Bazel will fall back to use patch command line tool if patch_tool attribute is specified or there are arguments other than -p in patch_args attribute.

recursive_init_submodulesBoolean; optional

Whether to clone submodules recursively in the repository.

remoteString; required

The URI of the remote Git repository

remote_module_file_integrityString; optional

For internal use only.

remote_module_file_urlsList of strings; optional

For internal use only.

repo_mappingDictionary: String -> String; optional

In WORKSPACE context only: a dictionary from local repository name to global repository name. This allows controls over workspace dependency resolution for dependencies of this repository.For example, an entry "@foo": "@bar" declares that, for any time this repository depends on @foo (such as a dependency on @foo//some:target, it should actually resolve that dependency within globally-declared @bar (@bar//some:target).This attribute is not supported in MODULE.bazel context (when invoking a repository rule inside a module extension’s implementation function).

shallow_sinceString; optional

an optional date, not after the specified commit; the argument is not allowed if a tag or branch is specified (which can always be cloned with —depth=1). Setting such a date close to the specified commit may allow for a shallow clone of the repository even if the server does not support shallow fetches of arbitrary commits. Due to bugs in git’s —shallow-since implementation, using this attribute is not recommended as it may result in fetch failures.

sparse_checkout_fileLabel; optional

File containing .gitignore-style patterns for a sparse checkout of files in this repository. Either sparse_checkout_patterns or sparse_checkout_file may be specified, or neither, but not both.

sparse_checkout_patternsList of strings; optional

Sequence of patterns for a sparse checkout of files in this repository.

strip_prefixString; optional

A directory prefix to strip from the extracted files.

tagString; optional

tag in the remote repository to checked out. Precisely one of branch, tag, or commit must be specified.

verboseBoolean; optional
workspace_fileLabel; optional

No-op attribute; do not use.

workspace_file_contentString; optional

No-op attribute; do not use.