Sub topic 12
Committing, pushing, and pulling changes
This chapter assumes you can already clone a repository into a Git folder and switch to a feature branch. It also assumes you know the basic Git ideas of commit, branch, push, pull, and merge. Here you will see how a change in a notebook becomes a commit, how it reaches the remote repository, and how changes made by others reach your workspace.
Two copies of the work
A Git folder holds a working copy of the repository inside the workspace. Your edits happen in that working copy. The remote repository, on GitHub, GitLab, Azure DevOps, or Bitbucket, is a separate copy that your teammates also use.
Nothing you type in a notebook reaches the remote until you commit and push. Nothing your teammates push reaches your workspace until you pull.
Seeing what changed
Open the Git dialog by selecting the branch name button at the top of the Git folder or notebook. The Changes tab lists each file you added, modified, or deleted since the last commit. Selecting a file shows a line-by-line diff.
A notebook is stored as a source file, so the diff shows code and magic lines, not rendered cells. A new cell appears like this:
# COMMAND ----------
df = spark.read.table("main.sales.orders")
display(df)The # COMMAND ---------- line is the cell separator. If the diff shows an unexpected separator or # MAGIC line, a cell boundary or cell language changed.
Committing
- Open the Git dialog on your feature branch.
- In the Changes tab, tick the files to include. Leave out files you did not mean to change.
- Write a commit message. It is required. Use a short summary line that says what changed and why.
- Select Commit & Push.
The workspace creates the commit in the Git folder and pushes the branch to the remote in one step. The commit author is taken from the Git credentials you configured. If your credentials are missing or invalid, the push fails, so check them first.
Commit small, related changes. A commit that changes one notebook and its helper module is easy to review. A commit that mixes five unrelated edits is not.
Pushing and what can block it
A push sends your local commits on the current branch to the same-named branch on the remote. It can fail for these common reasons:
| Symptom | Likely cause | Fix |
|---|---|---|
| Authentication or permission error | Expired token, or the token lacks write access | Update the Git credential, then retry |
| Push rejected on `main` | Branch protection requires a pull request | Push to a feature branch and open a pull request |
| Push rejected as non-fast-forward | The remote branch has commits you do not have | Pull first, then push |
Do not commit directly to main. Work on a feature branch, push it, and merge it through a pull request in your Git provider. The review step happens there, not in Databricks.
Pulling
Pulling brings new commits from the remote branch into your Git folder. Open the Git dialog and select Pull. The notebooks and files in the folder update to match.
Pull before you start work each day, and again before you push. Fewer surprises build up that way.
If you have uncommitted local edits to a file that also changed on the remote, the pull cannot apply cleanly. Databricks reports a merge conflict, and you must resolve it. Resolution is covered in the next chapter. To avoid it, commit or discard your own edits before pulling.
To bring the latest main into your feature branch, use the Merge or Rebase option in the Git dialog, choosing main as the branch to integrate. Then push the result. Merge keeps the full history and adds a merge commit. Rebase replays your commits on top of main for a linear history, but it rewrites commits and may require a force push if you had already pushed them.
The same steps in plain Git
The Git dialog performs standard Git operations. This sequence shows the equivalent commands on a laptop:
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-ordersLater, to update from the remote:
git pullIf you are comfortable with these commands, the dialog behaves the way you expect. The main difference is that you choose files in the Changes tab instead of running git add.
Notebook format and what gets committed
Each notebook is committed as a source file by default, so a Python notebook becomes a .py file, a SQL notebook a .sql file, and so on. Cell outputs, such as tables and charts, are not part of a source-format file. That keeps diffs clean and keeps result data out of your repository.
Databricks can also store notebooks in Jupyter .ipynb format. That format can include outputs, which makes diffs noisy and can leak data into the repository. Outputs are only committed when your workspace settings allow it, so check with your administrator before enabling it.
A review checklist before you push
- The Changes tab lists only files you meant to change.
- No credentials, tokens, or personal data appear in the diffs.
- Notebooks run top to bottom on a fresh cluster.
- The commit message says what changed and why.
- You pulled recently, so the push should be a fast-forward.
Common mistakes
- Editing on the wrong branch. Check the branch name at the top of the Git dialog before you edit. Committing to
mainby accident is the usual result of skipping this. - Forgetting to push. A commit alone is local. Teammates and jobs that read from the remote will not see it.
- Long-lived branches. The longer a branch lives, the more conflicts you face when you merge. Merge small changes often.
- Pulling with dirty edits. Commit or discard first.
Exercise
You edited a notebook on the branch feature/clean-orders and selected Commit & Push. A teammate says they cannot see your change on the remote main branch. What happened, and what should you do?
Show answer
Commit & Push sends the commit only to the remote branch feature/clean-orders, not to main. Your change will reach main only after the branch is merged, usually through a pull request in the Git provider. Open a pull request from feature/clean-orders into main, get it reviewed, and merge it. Your teammate can then pull main into their Git folder to see the change.
Exercise
A push from your Git folder is rejected as non-fast-forward. What is the cause, and what do you do?
Show answer
The remote branch has commits that your local branch does not have. Pull (or merge the remote branch) into your Git folder, resolve any conflicts, and then push again.