Sub topic 11
Cloning a repository and working on a branch
This chapter assumes you know basic Git (commit, branch, push, pull) and have already linked a Git provider credential to your Databricks user settings. Here you will clone a remote repository into a Git folder and create a feature branch to work on.
What cloning creates
A Git folder is a workspace folder tied to a remote repository. When you clone, Databricks copies the repository contents into the workspace and records the remote URL. Each Git folder holds one local clone and one checked-out branch at a time.
Put your Git folders under your own user folder, for example /Workspace/Users/<you>/. This keeps your working copy separate from your teammates' copies.
Clone the repository
- In the workspace sidebar, open Workspace, then go to your user folder.
- Select Create, then Git folder.
- Paste the repository URL, for example
https://github.com/your-org/orders-etl.git. - Choose the Git provider. It is often detected from the URL.
- Leave the folder name as is or change it, then select Create Git folder.
If the clone fails with an authentication error, check that your credential is saved for the same provider and that its token has access to this repository.
Switch to a feature branch
New clones start on the default branch, usually main. Don't edit that branch directly. Open the Git dialog from the branch button next to the folder name, then use the branch dropdown to create a new branch, for example feature/clean-orders. You can also select an existing remote branch to check it out.
The dialog performs the same steps as these Git commands:
git checkout -b feature/clean-ordersCommon problems
| Symptom | Likely cause |
|---|---|
| Authentication error on clone | Missing or expired token, or no access to the repository |
| Branch is missing from the dropdown | The branch exists only on the remote and has not been fetched. Pull, then reopen the list |
| Switching branches is blocked | You have uncommitted changes. Commit them first, or discard them |
Check your work
After creating the branch, open a notebook in the folder. The branch name should appear next to the Git folder name. Edits you make now belong to feature/clean-orders. They are not saved to the remote until you commit and push, which the next chapter covers.
Exercise
You cloned a repository and the Git dialog shows main. You want to change a notebook without affecting main. What should you do first, and why?
Show answer
Create a new feature branch from the Git dialog, for example feature/clean-orders, and make your edits there. Commits then go to the feature branch, and main stays unchanged until you merge through review.