Sub topic 9
Git folders: what they are and why use them
This chapter assumes you can run notebooks in the Databricks workspace and know basic Git terms: commit, branch, push, pull and merge. It describes what a Git folder is and how it differs from an ordinary workspace folder. It also covers the problems it solves and where it stops. Provider credentials, cloning, and commit and push are covered in later chapters.
What a Git folder is
A Git folder is a workspace folder that is linked to a remote Git repository. Databricks keeps a clone of the repository in the workspace. Notebooks, Python files, SQL files and other files in that folder are the working tree of that clone.
Git folders were previously called Databricks Repos. Older documentation, API paths and CLI commands may still use "repos".
A Git folder has these properties:
- It is tied to one remote repository URL and one provider, such as GitHub, GitLab, Azure DevOps or Bitbucket.
- It has one checked-out branch at a time.
- It belongs to the user who created it. Each person who works on the repository has their own Git folder.
- It supports Git operations from the workspace UI: create or switch branches, commit, push, pull, merge, rebase and resolve conflicts.
- It stores notebooks as source files, so a notebook diff in a pull request is a text diff.
A Git folder is not a full Git environment. The workspace runs the operations for you, but you cannot open a terminal in the folder and run arbitrary Git commands as you would on a laptop. Treat it as a managed clone with a limited set of operations.
Why not just use a workspace folder
An ordinary workspace folder keeps notebooks in the workspace only. Edits are saved and notebooks keep a revision history, but that history is local to the workspace. You cannot review a change, tie it to a ticket, or restore a whole set of files to a known state.
Git folders add the following:
| Need | Ordinary workspace folder | Git folder |
|---|---|---|
| Change history | Notebook revision history in the workspace | Commits in the remote repository |
| Parallel work | Everyone edits the same copy | Each person works on their own branch in their own folder |
| Code review | Not available | Pull requests on the Git provider |
| Reproducible runs | A job runs whatever the notebook currently contains | A job can run a specific branch, tag or commit |
| Backup and portability | Lives in the workspace | The remote repository is the source of truth |
| Automated tests and deployment | Manual | CI/CD can run on every push |
The last two rows matter most for production. A job that points at a workspace notebook can break when someone edits that notebook. A job that points at a tag in a repository only changes when you move the tag.
How the pieces fit together
The remote repository is the shared source of truth. Each user's Git folder is a private working copy, much like a clone on a laptop. The difference is that the clone lives in the workspace and is attached to Databricks compute.
Two consequences follow from this model:
- Edits in your Git folder are private until you commit and push them. Another user does not see your uncommitted edits, even though you share a workspace.
- Pulling is how you receive other people's work. A Git folder does not update itself when the remote changes.
What is stored and what is not
The folder holds the files Git tracks. A notebook appears in the folder as a notebook object, but in the repository it is a text file. A Python notebook is a .py file with a header comment and cell markers. The next chapters cover that format in detail.
Several other things matter here:
- Notebook results and outputs are not committed by default. A teammate who pulls your branch gets the code, not your last output.
- Files other than notebooks, such as
.pymodules,.sqlfiles,.jsonconfiguration andREADME.md, are kept as ordinary files. You can import Python modules from them, which a later chapter covers. - Git ignores whatever your
.gitignoreexcludes, as in any clone. - Clusters and permissions are workspace settings. They are not part of the repository.
You can check where a notebook runs from. When a notebook in a Git folder runs on compute that supports workspace files, the current working directory is the folder containing the notebook.
import os
print(os.getcwd())
print(sorted(os.listdir(".")))In a Git folder this prints a path under /Workspace/, followed by the files next to the notebook. This is how relative paths to config files or modules resolve.
Typical lifecycle
A normal change moves through these steps:
- Open your Git folder and create a branch from the main branch.
- Edit notebooks and files, and run them on compute.
- Commit with a message, then push the branch to the remote.
- Open a pull request on the Git provider and get it reviewed.
- Merge on the provider. Pull the main branch into a Git folder when you need the merged result.
- Run jobs from the main branch or a release tag.
Step 5 shows a boundary worth remembering. Merging a pull request happens on the provider. Your Git folder changes only when you pull.
Limits and common errors
Git folders have constraints that cause most first-week problems:
- Working on the production branch directly. If a scheduled job reads from a Git folder's branch and someone commits to it, the job changes. Use a dedicated branch or tag for production, and develop on feature branches.
- Expecting live collaboration. Two people editing the same notebook in one Git folder overwrite each other. Give each person a separate Git folder and let Git merge the changes.
- Forgetting to pull. If you do not pull, you edit stale code. A later push may be rejected, or it may produce a merge conflict.
- Missing credentials. Git operations fail until the workspace has a valid personal access token or linked account for the provider. A later chapter covers this.
- Very large repositories. Repositories and individual files above the documented size limits fail to clone or commit. Check the current limits for your workspace, and consider sparse checkout when you need only part of a large repository.
- Binary and output-heavy notebooks. Notebooks with large embedded outputs produce noisy diffs. Clear outputs before committing where your team's policy requires it.
When Git folders are the right tool
Use Git folders when the code needs review, history and repeatable deployment. For one-off exploration, a plain workspace notebook is faster, and you can move it into a Git folder later. A reasonable rule is that anything a job or a teammate depends on belongs in a repository.
Exercise
A scheduled job runs a notebook from your Git folder's main branch. A teammate pushes a fix to the remote main branch. Why does your job still run the old code, and what two settings or actions would make runs predictable?
Show answer
A Git folder does not update on its own. It changes only when someone pulls. The old code stays until the folder is pulled. To make runs predictable, point the job at a Git source with a specific branch, tag or commit, so the job reads the repository directly. Alternatively, keep the folder pulled by a controlled process. Also keep development on feature branches and move a release tag when you want production to change.
Exercise
Two analysts need to edit the same notebook at the same time. Describe how to arrange this with Git folders.
Show answer
Each analyst clones the repository into their own Git folder and creates their own branch. They commit and push, then merge through a pull request on the provider. Git resolves overlapping edits as merge conflicts, which they fix before merging. They should not edit one shared Git folder.