Chapter 3: Branching, Merge and GitHub PRs
3.1 Why branches — two developers, one shared app
Imagine two developers editing one shared app file. One changes badge colour. The other adds a new field. If both overwrite the same file on a USB stick, one person's work disappears.
A branch in Git is a movable label that points at a commit. Creating a branch gives you a separate line of work. You can finish your change, then merge it back into the shared line (usually main).
Why it matters for an Instagram-style badge API : one developer adds GET /health while another edits the badge field. Separate branches keep unfinished work off the live line until a review says it is ready.
| Without branches | With feature branches |
|---|---|
Everyone commits on main |
Each change lives on its own branch |
| Broken half-work can hit production | main stays releasable |
| Hard to review one idea | Pull request shows one focused diff |
| Conflicts surprise you late | You merge when ready and fix conflicts once |
Ravindra Bagale's Tip
Khup students team madhe thodach main var commit kartat. Companies madhe main protected aste — direct push band. Nehmi feature branch + pull request. Lakshat theva!