Sub topic 16
Running jobs from a Git source
This chapter assumes you can write a notebook with widgets, you know how to commit and push from a Git folder, and you have created a basic job in the Jobs UI.
Why run a job from Git
A job can run a notebook from a Git folder in the workspace. That copy is whatever someone last pulled, so the job may run stale or half-edited code. A job with a Git source avoids this. At each run, Databricks fetches the notebook from the remote repository at the branch, tag, or commit you named. The run uses exactly that version.
How a run works
Configuring the Git source
In the job's task settings, set Source to Git provider and fill in three things:
- The repository URL.
- A reference type: branch, tag, or commit.
- The notebook path, relative to the repository root and without a file extension.
The job stores one Git reference, and every task in the job uses it. Notebooks, Python scripts, SQL files, and dbt tasks can read from Git.
The same setup in a Jobs API payload looks like this:
{
"name": "daily-load",
"git_source": {
"git_url": "https://github.com/example-org/orders-etl",
"git_provider": "gitHub",
"git_branch": "main"
},
"tasks": [
{
"task_key": "load",
"notebook_task": {
"notebook_path": "notebooks/daily_load",
"source": "GIT",
"base_parameters": { "run_date": "2026-01-01" }
},
"job_cluster_key": "etl_cluster"
}
]
}The payload leaves out the job_clusters definition that etl_cluster refers to. Add one before you submit it.
Passing parameters
The notebook needs no changes to run in a job. The job's parameters fill the widgets you already defined:
dbutils.widgets.text("run_date", "2026-01-01", "Run date")
run_date = dbutils.widgets.get("run_date")
print(f"Processing {run_date}")When the job supplies run_date, the widget takes that value. Otherwise it keeps its default.
Pinning versus following a branch
| Reference | Behavior | Use for |
|---|---|---|
| Branch | Each run takes the latest commit on that branch | Development and staging |
| Tag | Each run uses the tagged release | Production |
| Commit | Each run uses one exact commit | Reproducing a past run |
A production job that follows main picks up every merge. Pin production to a tag if you want releases to be deliberate.
Common errors
- Path with an extension. Use
notebooks/daily_load, notnotebooks/daily_load.py. - Wrong path root. The path starts at the repository root, not at your workspace folder.
- Missing credentials. The job needs Git credentials for a public repository's rate limits or for any private repository. Databricks uses the credentials of the job's run-as identity. If the run fails at clone time, check that identity's linked Git credential.
- Branch deleted after merge. A job pointing at a removed feature branch fails to fetch.
Exercise
A production job runs notebooks/daily_load.py from branch main, and the run fails before any code executes. Name two likely causes.
Show answer
The notebook path should not include the .py extension, so it should be notebooks/daily_load. The run-as identity may also lack a valid Git credential for the repository, so the clone fails. (A deleted or misspelled branch name is another possible cause.)