Sync Snowflake Notebooks with a Git repository

To use version control with your Snowflake Notebooks, you can sync your notebook development with a branch in a Git repository.

You must have already set up your Snowflake account to be connected to a Git repository and have created a branch in that repository to use for your notebook development. See Setting up Snowflake to use Git.

Create a notebook from a file in a Git repository

Note

The file must be an .ipynb formatted file and it must use notebook format (nbformat) 4.0 or higher.

To create a Snowflake Notebook from a file in a Git repository, do the following:

  1. Sign in to Snowsight.

  2. Select Projects » Notebooks.

  3. Next to + Notebook, open the drop-down menu and select Create from repository.

  4. For File location in repository, select the repository and branch in the repository that contain the notebook file, then select the specific .ipynb file.

  5. For Notebook location, select a database and schema to contain the notebook. These cannot be changed after you create the notebook.

  6. For Notebook warehouse, select a warehouse.

  7. Select Create to create a Snowflake Notebook from the .ipynb file in your Git repository.

Connect an existing notebook with a Git repository

To connect an existing Snowflake notebook to a Git repository, do the following:

Note

You must use a role with the following privileges at a minimum:

  • OWNERSHIP or READ privilege on the Git repository.

  • USAGE privilege on the schema that contains the Git repository.

See Access control requirements.

  1. Sign in to Snowsight.

  2. Select Projects » Notebooks and open or create a Snowflake Notebook.

  3. In the Files tab, next to the database object explorer, select Connect Git Repository.

  4. For File location in repository, select the repository and branch in the repository with which you want to sync the notebook.

  5. Select Select Folder.

  6. Next you are prompted to commit your notebook to the Git repository. Complete the commit steps outlined in Commit changes to a branch in a Git repository section.

After connecting your notebook with a Git repository, you can select the branch name and open the repository details in Snowflake or on Github.

Commit changes to a branch in a Git repository

If a Snowflake Notebook is connected to a branch in a Git repository, after you make changes to the Snowflake Notebook you can commit your changes to the branch.

You must use a role with the OWNERSHIP or WRITE privilege on the Git repository to commit your changes. See Access control requirements.

  1. Sign in to Snowsight.

  2. Select Projects » Notebooks and open a Snowflake Notebook.

  3. Make any relevant changes to the notebook.

  4. Select Commit.

  5. In the Commit to Repository dialog that displays, you can review the username and email address that are used to commit the changes to the specified branch and repository. If you need to update the username and email address, expand the Credentials section and update the Author name and Author email.

  6. For Commit message, enter a message to include with your commit.

  7. Expand the Credentials section to configure credentials. Enter your personal access token for the Git repository in the Personal access token field. This access token comes from the remote Git provider, such as Github.

    • This token is required to authenticate to the Git repository.

    • The token must have read and write access to the content of the repository for the commit to work.

    • Once entered, the token will be saved for future commits. You can update it during any future commits.

  8. Select Commit.

A confirmation message states that your changes were committed to your branch.

Sync a notebook with a remote branch in a Git repository

After you connect your notebook to a branch in a Git repository, you can sync any changes in the remote branch with your Snowflake Notebook.

  1. Sign in to Snowsight.

  2. Select Projects » Notebooks and open or create a Snowflake Notebook.

  3. In the database object explorer, in the Files tab, select Pull.

Snowflake fetches any changes present on the remote repository branch and merges the notebook contents with those changes.

Merge conflicts

Snowflake attempts to resolve merge conflicts that occur during a sync. If there are merge conflicts that Snowflake isn’t able to resolve, you will get a message to either discard your changes or commit them to a new branch. When they are committed to a new branch, use your Git provider to manually merge your changes from the new branch to the original branch. Then you should pull the latest updates into your Snowflake notebook.