Snowflake

Snowflake Git Integration: Version-Control SQL Scripts and Notebooks

2026-03-26
Updated: 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: create the Secret (credentials)
  ↓
Step 2: create the API Integration (connection to the Git API)
  ↓
Step 3: create the Git Repository object
  ↓
Step 4: sync with the remote using FETCH
  ↓
Step 5: reference files and run scripts

Step 1: Create the authentication Secret

-- Store a GitHub Personal Access Token (PAT)
CREATE OR REPLACE SECRET git_pat_secret
  TYPE = PASSWORD
  USERNAME = 'github-username'
  PASSWORD = 'ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';

-- A Secret is not needed for public repositories

Step 2: Create the API Integration

-- API Integration for GitHub
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

-- Create the Git Repository object
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';

-- For a public repository (no authentication)
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

-- Pull the latest from the remote repository
ALTER GIT REPOSITORY analytics_db.public.my_sql_repo FETCH;

-- List the branches
SHOW GIT BRANCHES IN analytics_db.public.my_sql_repo;

-- List the tags
SHOW GIT TAGS IN analytics_db.public.my_sql_repo;

Browsing Files

-- List the files on the main branch
LIST @analytics_db.public.my_sql_repo/branches/main/;

-- List the files in a specific directory
LIST @analytics_db.public.my_sql_repo/branches/main/sql/transforms/;

-- List the files at a specific tag
LIST @analytics_db.public.my_sql_repo/tags/v1.2.0/;

-- Read a file's contents
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

-- Run a SQL script from the Git Repository directly
EXECUTE IMMEDIATE FROM
  @analytics_db.public.my_sql_repo/branches/main/sql/create_tables.sql;

-- Run the script from a specific tag (version)
EXECUTE IMMEDIATE FROM
  @analytics_db.public.my_sql_repo/tags/v1.2.0/sql/migrations/001_add_columns.sql;

-- Run the script with variables
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

-- Automate FETCH -> run script with a Task
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

Question 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

Correct answer: 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

Try free questions
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.