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.
| Course | Git Basics Course · Module 3 of 7 · Stage 1 "On your own" |
| Learn | What a branch and HEAD really are, creating and switching branches, merging, resolving conflicts |
| How | 4 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-forward | Merge commit (--no-ff) | |
|---|---|---|
| When | main hasn't moved since you branched | both branches have new commits |
| History | a straight line | a visible "feature merged here" point |
| Conflicts | never | possible, 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?