Sub topic 9
Git folders: what they are and why use them
This chapter assumes you know basic Git (commit, branch, push, pull, merge) and can move around the Databricks workspace UI. It explains what a Git folder is and when to use one. Later chapters cover connecting a provider, cloning, and committing.
What a Git folder is
A Git folder is a workspace folder that is linked to a remote Git repository. Databricks keeps a local clone of the repository inside the workspace. You edit notebooks and files in that clone, and you use the Git dialog in the workspace to run Git operations against the remote.
The remote repository, hosted on a provider such as GitHub, GitLab, Azure DevOps, or Bitbucket, remains the source of truth. The Git folder is a working copy of it.
Why use one
Without Git, a notebook lives only in the workspace. Revision history shows earlier versions, but it is tied to that one notebook. It has no branches, no code review, and no link to the rest of your project.
A Git folder gives you the following:
- Branches. Each person can work on a feature branch without changing the shared version.
- Code review. Changes reach the main branch through pull requests on your provider.
- A real history. Commits carry messages and authors, and they cover many files at once.
- Files beyond notebooks. Python modules, SQL files, and configuration can live next to the notebooks.
- Automation. Jobs and deployment tools can read code from the repository instead of from someone's personal folder.
How it differs from revision history
| Feature | Notebook revision history | Git folder |
|---|---|---|
| Scope | One notebook | Whole repository |
| Branching | No | Yes |
| Review process | No | Pull requests on the provider |
| Lives outside the workspace | No | Yes, on the remote |
| Works for non-notebook files | No | Yes |
What you can and cannot do in the workspace
You can create, edit, and run notebooks in a Git folder as you would anywhere else. You can also commit, push, pull, and switch branches from the Git dialog. Some operations are done on the provider instead. Examples are opening a pull request, approving it, and merging it.
Each user normally works in their own Git folder, which is their own clone. Two people editing the same clone would overwrite each other's uncommitted work, so avoid sharing one.
Common mistakes
- Treating the workspace as the master copy. Edits made in the Git folder do not reach the repository until you commit and push.
- Working on the main branch directly. Create a feature branch first. This keeps main reviewable.
- Sharing one Git folder between several people. Give each person their own clone.
Exercise
A teammate says, "I changed the notebook in my Git folder yesterday, so it's in the repository now." What is missing from that claim, and where else can the team see the change once it is done properly?
Show answer
The change must be committed and pushed to the remote. Until then it exists only in the workspace clone. After the push, the team can see it on the remote branch and in a pull request on the Git provider.