Sub topic 12
Committing, pushing, and pulling changes
This chapter assumes you can run Databricks notebooks, know basic Git terms (commit, branch, push, pull, merge), and have already cloned a repository into a Git folder and switched to a feature branch.
How the Git folder maps to Git
A Git folder holds a local clone of the repository inside the workspace. Edits to a notebook change the workspace copy only. Nothing reaches the remote repository until you commit and push.
The workspace Git dialog exposes the same steps you would run on a command line. Notebooks are saved as source files (the # Databricks notebook source format), so the diffs you review are readable text.
Commit and push
In the workspace, open the Git dialog from the branch name in the notebook or folder header. The dialog lists changed files. Select the files to include, write a commit message, and choose Commit & Push.
The dialog does the same work as these commands:
git checkout -b feature/clean-orders
# edit notebooks in the Git folder, then:
git add -A
git commit -m "Clean orders notebook"
git push -u origin feature/clean-ordersWrite messages that say what changed, such as "Clean orders notebook". Small, focused commits make code review easier.
Pull
Pull brings the latest commits from the remote branch into the Git folder. Pull before you start work and again before you push, so your branch is current.
Pull can fail if you have uncommitted changes to the same files that changed on the remote. Commit your edits first, then pull. If both sides changed the same lines, you get a merge conflict, which the next chapter covers.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| Push is rejected | The remote branch has newer commits | Pull, resolve any conflicts, then push again |
| Authentication error on push | The Git credential is missing, expired, or lacks write access | Update the token in the workspace Git settings |
| Pull is blocked by local changes | Uncommitted edits overlap with incoming changes | Commit the edits, then pull |
| You committed on the wrong branch | The Git folder was on `main` | Switch to a feature branch and make the change there |
A typical cycle
- Pull the latest changes for your branch.
- Edit the notebook and run it to check the result.
- Open the Git dialog and review the changed files.
- Commit with a clear message and push.
- Open a pull request in your Git provider.
Exercise
You edited a notebook in a Git folder, and a teammate pushed a change to the same branch. A push from the Git dialog is rejected. What should you do?
Show answer
Commit your local edits if you have not already, pull the teammate's commits into the Git folder, resolve any merge conflicts, and then push again. The push was rejected because the remote branch had commits your local branch did not have.