Branching

Several tasks in parallel without breaking working code: branches, merges and conflicts as routine.

4 lessons8 interview questions4 terminal practices

An urgent bug lands in the middle of your feature. What now? Without branches you either ship half-done code or stash it in a folder copy. With branches you switch in one command, fix, merge, and come back. And CONFLICT turns out not to be an error, just a question Git asks you.

CourseGit Basics Course · Module 3 of 7 · Stage 1 "On your own"
LearnWhat a branch and HEAD really are, creating and switching branches, merging, resolving conflicts
How4 lessons on my-plugin with main, feature/cart-update and feature/tax, merged and conflicted in the browser terminal

A feature and a hotfix, side by side

gitGraph
  commit id: "v1.0"
  branch feature/cart-update
  checkout feature/cart-update
  commit id: "cart: new totals"
  checkout main
  branch hotfix/tax
  checkout hotfix/tax
  commit id: "fix: tax rounding"
  checkout main
  merge hotfix/tax
  checkout feature/cart-update
  commit id: "cart: tests"
  checkout main
  merge feature/cart-update

A branch is not a copy of the project. It's a pointer to a commit, so creating one is instant and free.

Two ways to merge

Fast-forwardMerge commit (--no-ff)
Whenmain hasn't moved since you branchedboth branches have new commits
Historya straight linea visible "feature merged here" point
Conflictsneverpossible, and you'll resolve them by hand

You'll be able to answer

  • What is a Git branch technically?
  • What is a detached HEAD?
  • What's the difference between fast-forward and a merge commit?
  • How do you undo a merge that went wrong?

Lessons in this module 4 lessons