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.

main = official shared version
your branch = your workspace for a proposed change

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.

Run:

Terminal window
git checkout -b docs/practice-change

or:

Terminal window
git switch -c docs/practice-change
  • 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 add filename
git commit -m "docs: make practice branch change"
  • I committed a change on my branch.

Run:

Terminal window
git push -u origin docs/practice-change
  • My branch exists on GitHub.
docs/update-readme
analysis/add-summary-table
fix/correct-date-label
feature/add-data-dictionary
  • I can create a branch.
  • I can switch branches.
  • I can commit on a branch.
  • I can push a branch to GitHub.