Lesson 06 — Branching
Create a branch so you can work safely without changing main directly.
What a branch is
Section titled “What a branch is”A branch is a separate workspace for a change.
Instead of editing main directly, create a branch for your work.
main = official shared versionyour branch = your workspace for a proposed changeChecklist
Section titled “Checklist”1. Start from main
Section titled “1. Start from main”Run:
git checkout mainor:
git switch main- I am on
main.
2. Pull the latest main
Section titled “2. Pull the latest main”Run:
git pull- My local
mainis up to date.
3. Create a new branch
Section titled “3. Create a new branch”Run:
git checkout -b docs/practice-changeor:
git switch -c docs/practice-change- I created and switched to a new branch.
4. Confirm the current branch
Section titled “4. Confirm the current branch”Run:
git branchThe current branch has an asterisk next to it.
- I can identify my current branch.
5. Make and commit a change
Section titled “5. Make and commit a change”Use the workflow from Lesson 04:
git statusgit add filenamegit commit -m "docs: make practice branch change"- I committed a change on my branch.
6. Push the branch to GitHub
Section titled “6. Push the branch to GitHub”Run:
git push -u origin docs/practice-change- My branch exists on GitHub.
Branch naming examples
Section titled “Branch naming examples”docs/update-readmeanalysis/add-summary-tablefix/correct-date-labelfeature/add-data-dictionaryCompletion check
Section titled “Completion check”- I can create a branch.
- I can switch branches.
- I can commit on a branch.
- I can push a branch to GitHub.