CREATE GIT REPOSITORY

在架构中创建 Snowflake Git 存储库克隆或替换现有的 Git 存储库克隆。

For an overview, see Using a Git repository in Snowflake.

See also:

ALTER GIT REPOSITORY, DESCRIBE GIT REPOSITORY, DROP GIT REPOSITORY, SHOW GIT BRANCHES, SHOW GIT REPOSITORIES, SHOW GIT TAGS

语法

CREATE [ OR REPLACE ] GIT REPOSITORY [ IF NOT EXISTS ] <name>
  ORIGIN = '<repository_url>'
  API_INTEGRATION = <integration_name>
  [ GIT_CREDENTIALS = <secret_name> ]
  [ COMMENT = '<string_literal>' ]
  [ [ WITH ] TAG ( <tag_name> = '<tag_value>' [ , <tag_name> = '<tag_value>' , ... ] ) ]

必填参数

name

指定要创建的 Git 存储库克隆的标识符。

If the identifier contains spaces or special characters, the entire string must be enclosed in double quotes. Identifiers enclosed in double quotes are also case-sensitive.

For more information, see Identifier requirements.

ORIGIN = 'repository_url'

指定此 Git 存储库克隆所代表的远程 Git 存储库的来源 URL。该 URL 必须使用 HTTPS。

Snowflake 支持任何 HTTPS Git 存储库 URL。例如,您可以在自己的域内为企业 Git 服务器指定自定义 URL。

From the command line, you can use the git config command from within your local repository to get the value to use for the ORIGIN parameter, as shown in the following example:

$ git config --get remote.origin.url
https://github.com/mycompany/My-Repo.git
API_INTEGRATION = integration_name

Specifies the API INTEGRATION that contains information about the remote Git repository such as allowed credentials and prefixes for target URLs.

The API integration you specify here must have an API_PROVIDER parameter whose value is set to git_https_api.

For reference information about API integrations, see CREATE API INTEGRATION.

可选参数

GIT_CREDENTIALS = secret_name

Specifies the Snowflake secret containing the credentials to use for authenticating with the remote Git repository. Omit this parameter to use the default secret specified by the API integration or if this integration does not require authentication.

As a best practice, use a personal access token for the secret’s PASSWORD value. For information about creating a personal access token in GitHub, see Managing your personal access tokens (https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens) in the GitHub documentation.

此处指定的密钥必须是由您使用此命令的 API_INTEGRATION 参数指定的 API 集成的 ALLOWED_AUTHENTICATION_SECRETS 参数指定。

默认:无值

For reference information about secrets, see CREATE SECRET.

COMMENT = 'string_literal'

Specifies a comment for the Git repository clone.

默认:无值

TAG ( tag_name = 'tag_value' [ , tag_name = 'tag_value' , ... ] )

Specifies the tag name and the tag string value.

The tag value is always a string, and the maximum number of characters for the tag value is 256.

For information about specifying tags in a statement, see Tag quotas.

访问控制要求

A role used to execute this operation must have the following privileges at a minimum:

权限对象备注
CREATE GIT REPOSITORY架构
USAGEAPI 集成此命令的 API INTEGRATION 参数指定的集成
USAGE密钥此命令的 GIT_CREDENTIALS 参数指定的密钥

Operating on an object in a schema requires at least one privilege on the parent database and at least one privilege on the parent schema.

For instructions on creating a custom role with a specified set of privileges, see Creating custom roles.

For general information about roles and privilege grants for performing SQL actions on securable objects, see Overview of Access Control.

使用说明

  • The OR REPLACE and IF NOT EXISTS clauses are mutually exclusive. They can’t both be used in the same statement.
  • CREATE OR REPLACE <object> statements are atomic. That is, when an object is replaced, the old object is deleted and the new object is created in a single transaction.

示例

Code in the following example creates a Git repository clone called snowflake_extensions, where the remote repository’s origin URL is https://github.com/my-account/snowflake-extensions.git. The example uses an API integration called git_api_integration. It also uses a secret called git_secret to store credentials for authenticating with the remote repository.

For details about setting up integration with a remote Git repository, see Setting up Snowflake to use Git.

CREATE OR REPLACE GIT REPOSITORY snowflake_extensions
  API_INTEGRATION = git_api_integration
  GIT_CREDENTIALS = git_secret
  ORIGIN = 'https://github.com/my-account/snowflake-extensions.git';