Skip to content

Lesson 06 — Branching

Create a branch so you can work safely without changing main directly.

A branch is a separate workspace for a change.

Instead of editing main directly, create a branch for your work.

Diagram showing main as the stable shared line and a branch splitting off as a safe workspace for one proposed change.

branch namedescription
mainofficial shared version
your branchyour workspace for a proposed change

Diagram showing main on your computer and origin/main on GitHub, plus a new local branch that appears on GitHub only after you push it.

A branch starts on your computer. It appears on GitHub after you push it.

Run:

Terminal window
git checkout main

or:

Terminal window
git switch main
  • I am on main.

Run:

Terminal window
git pull
  • My local main is up to date.

For a SQL query documentation change, run:

Terminal window
git checkout -b analysis/clarify-visit-query

or:

Terminal window
git switch -c analysis/clarify-visit-query
  • I created and switched to a new branch.

Run:

Terminal window
git branch

The current branch has an asterisk next to it.

  • I can identify my current branch.

Use the workflow from Lesson 04:

Terminal window
git status
git diff
git add queries/01-count-visits.sql
git commit -m "docs: clarify visit count query"
  • I committed a change on my branch.

Run:

Terminal window
git push -u origin analysis/clarify-visit-query
  • My branch exists on GitHub.
docs/add-analysis-note
analysis/clarify-visit-query
metadata/define-visit-date
fix/correct-county-label

Use names that describe the change. Avoid branch names like updates, work, or stuff.

  • I can create a branch.
  • I can switch branches.
  • I can commit on a branch.
  • I can push a branch to GitHub.
  • I understand that a branch is safer than editing main directly.