Module 6 · ~40 min

Branches & merging

Goal: Work on features safely without breaking the stable main branch.

Why branches?

main should stay working. Branches let you build features in isolation, then merge when ready.

Practice exercise

  1. Create a branch: git switch -c add-about-page
  2. Edit files and commit on the branch.
  3. Push: git push -u origin add-about-page
  4. On GitHub: Pull requests → New — base main, compare your branch.
  5. Review Files changedMerge pull request.
  6. Locally: git switch main then git pull origin main

Merge conflicts (brief)

If two branches edit the same lines, resolve conflict markers in the file, then git add and git commit.

CommandPurpose
git branchList local branches
git switch <name>Change branch
git merge <branch>Merge into current branch

Checklist

  • I created a branch and committed on it
  • I opened and merged a pull request
  • I updated local main with git pull