Snowflake

Snowflake Git Integration: Version-Control SQL Scripts and Notebooks

2026-03-26
更新: 2026-03-27
NicheeLab Editorial Team

Snowflake Git Integration registers a Git repository (GitHub, GitLab, etc.) as a Snowflake database object, letting you directly reference and execute the SQL scripts, Python files, and configuration files it contains from inside Snowflake. It's a great fit for Infrastructure as Code (IaC) and CI/CD pipeline integration, and you can also use it to version-control Snowflake Notebooks.

Git Integration Setup Flow

Step 1: Secret(認証情報)の作成
  ↓
Step 2: API Integration(Git API接続)の作成
  ↓
Step 3: Git Repositoryオブジェクトの作成
  ↓
Step 4: FETCH でリモートと同期
  ↓
Step 5: ファイル参照・スクリプト実行

Step 1: Create the authentication Secret

-- GitHubのPersonal Access Token (PAT) を格納
CREATE OR REPLACE SECRET git_pat_secret
  TYPE = PASSWORD
  USERNAME = 'github-username'
  PASSWORD = 'ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';

-- パブリックリポジトリの場合はSecretは不要

Step 2: Create the API Integration

-- GitHub用のAPI Integration
CREATE OR REPLACE API INTEGRATION github_api_integration
  API_PROVIDER = git_https_api
  API_ALLOWED_PREFIXES = ('https://github.com/my-org/')
  ALLOWED_AUTHENTICATION_SECRETS = (git_pat_secret)
  ENABLED = TRUE;

Step 3: Create the Git Repository

-- Git Repositoryオブジェクトの作成
CREATE OR REPLACE GIT REPOSITORY analytics_db.public.my_sql_repo
  API_INTEGRATION = github_api_integration
  GIT_CREDENTIALS = git_pat_secret
  ORIGIN = 'https://github.com/my-org/snowflake-sql-scripts.git';

-- パブリックリポジトリの場合(認証なし)
CREATE OR REPLACE GIT REPOSITORY analytics_db.public.public_repo
  API_INTEGRATION = github_api_integration
  ORIGIN = 'https://github.com/my-org/public-scripts.git';

Step 4: Fetch from the remote repository

-- リモートリポジトリの最新を取得
ALTER GIT REPOSITORY analytics_db.public.my_sql_repo FETCH;

-- ブランチ一覧を確認
SHOW GIT BRANCHES IN analytics_db.public.my_sql_repo;

-- タグ一覧を確認
SHOW GIT TAGS IN analytics_db.public.my_sql_repo;

Browsing Files

-- mainブランチのファイル一覧
LIST @analytics_db.public.my_sql_repo/branches/main/;

-- 特定ディレクトリのファイル一覧
LIST @analytics_db.public.my_sql_repo/branches/main/sql/transforms/;

-- 特定タグのファイル一覧
LIST @analytics_db.public.my_sql_repo/tags/v1.2.0/;

-- ファイルの内容を読み取り
SELECT $1 AS content
FROM @analytics_db.public.my_sql_repo/branches/main/README.md
(FILE_FORMAT => 'util_db.formats.text_raw');

Executing SQL Scripts

-- Git Repository内のSQLスクリプトを直接実行
EXECUTE IMMEDIATE FROM
  @analytics_db.public.my_sql_repo/branches/main/sql/create_tables.sql;

-- 特定タグ(バージョン)のスクリプトを実行
EXECUTE IMMEDIATE FROM
  @analytics_db.public.my_sql_repo/tags/v1.2.0/sql/migrations/001_add_columns.sql;

-- 変数を渡してスクリプトを実行
EXECUTE IMMEDIATE FROM
  @analytics_db.public.my_sql_repo/branches/main/sql/parameterized_query.sql
  USING (target_date => '2026-03-27', batch_size => 10000);

Git Repository Path Structure

Path formatWhat it referencesExample
@repo/branches/<branch>/Latest commit on a branch@my_repo/branches/main/sql/
@repo/tags/<tag>/Commit pinned to a specific tag@my_repo/tags/v1.0.0/sql/
@repo/commits/<hash>/A specific commit hash@my_repo/commits/abc123/sql/

Integration with Snowflake Notebooks

By linking a Snowsight Notebook to a Git repository, the Notebook's versions are managed through Git.

  • Connect a Git repository to a Notebook from the Snowsight UI
  • Switch branches, commit, and push directly from the UI
  • Multiple data scientists can collaborate on the same Notebook through branches
  • Run pull-request-based review workflows on GitHub or GitLab

CI/CD Pipeline Pattern

-- TaskでFETCH → スクリプト実行を自動化
CREATE OR REPLACE TASK daily_deploy
  WAREHOUSE = ops_wh
  SCHEDULE = 'USING CRON 0 6 * * * UTC'
AS
  BEGIN
    ALTER GIT REPOSITORY my_sql_repo FETCH;
    EXECUTE IMMEDIATE FROM
      @my_sql_repo/branches/main/sql/daily_etl.sql;
  END;

ALTER TASK daily_deploy RESUME;

Required Privileges

OperationRequired privilege
CREATE GIT REPOSITORYCREATE GIT REPOSITORY on the schema
ALTER GIT REPOSITORY FETCHOWNERSHIP or MONITOR on the Git Repository
EXECUTE IMMEDIATE FROM @repoREAD on the Git Repository plus execute privileges for the SQL inside the script
LIST @repoREAD on the Git Repository

Best Practices

  • Tag-based deployments: in production, reference tags rather than branches so you execute a known, pinned version of the script.
  • Schedule periodic FETCH with a Task: run FETCH on a schedule via a Task so manual fetches don't get missed.
  • Tighten API_ALLOWED_PREFIXES: narrow the API Integration's API_ALLOWED_PREFIXES to the smallest set of repositories you actually need.
  • Rotate Secrets: set an expiration on Personal Access Tokens and rotate the Secret on a regular cadence.

Check Your Understanding

DevOps & Git

問題 1

You want to register a private GitHub repository as a Snowflake Git Repository. Which combination of objects must be created before running CREATE GIT REPOSITORY?

  1. Storage Integration and External Stage
  2. Secret (storing the PAT) and API Integration (git_https_api)
  3. Network Rule and External Access Integration
  4. Security Integration and OAuth token

正解: B

Connecting to a private Git repository requires two objects: (1) a Secret (TYPE = PASSWORD) that stores the Personal Access Token, and (2) an API Integration with API_PROVIDER = git_https_api. CREATE GIT REPOSITORY then references the Secret in GIT_CREDENTIALS and the API Integration in API_INTEGRATION. Storage Integration is for Stages, and Network Rule is for External Access Integration — neither is used for Git Integration.

Frequently Asked Questions

Which Git providers does Snowflake's Git Integration support?

Snowflake supports any Git repository reachable over HTTPS, including GitHub, GitLab, Bitbucket, and Azure DevOps Repos. The SSH protocol is not supported, so you must register repositories using their HTTPS URLs. For private repositories, authenticate by storing a Personal Access Token (PAT) in a Secret object.

Is the content of a registered Git Repository synced in real time?

No, the sync is not automatic. You must run ALTER GIT REPOSITORY ... FETCH manually or schedule it with a Task to pull the latest content from the remote. Once fetched, you can access files on specific branches or tags via SQL queries. FETCH operations are billed in Serverless Credits.

Can I use files inside a Git Repository as a source for COPY INTO?

Not directly. A Git Repository is intended for managing code and scripts, not for bulk data loading the way a Stage is. However, you can drive data pipelines indirectly by executing SQL scripts stored in the repository, for example EXECUTE IMMEDIATE FROM @git_repo/branches/main/scripts/load.sql.

Check what you learned with practice questions

Practice with certification-focused question sets

無料で問題を解いてみる
Author

NicheeLab Editorial Team

NicheeLab editorial team focused on data engineering and cloud certification learning. Content is structured around practical study needs and official exam domains.


Related articles
Snowflake

Snowflake Certifications: All 11 Exams Explained (2026)

Every SnowPro certification — Associate, Core, Specialty, Ad...

Snowflake

Snowflake Exam Difficulty Ranking: All 11 Certs Compared (2026)

All 11 SnowPro exams ranked by difficulty with study-time es...

Snowflake

Snowflake Study Guide: Fastest Pass Route by Exam (2026)

How to pass SnowPro certifications efficiently — official ma...

Snowflake

SnowPro Core (COF-C03): Complete Exam Guide (2026)

Pass the SnowPro Core exam — six domains, scope, sample ques...

Snowflake

SnowPro Associate Platform (SOL-C01): Complete Guide (2026)

The entry-level SnowPro Associate exam — scope, weighting, s...

Browse all Snowflake articles (103)
© 2026 NicheeLab All rights reserved.