The Plain Picture#
A newspaper: reporters write drafts separately; an editor reviews each draft before it goes into the printed edition; the printed edition is always in a publishable state.
The Real Names#
mainis the printed edition: always working, always deployable. Nobody commits to it directly.A feature branch is one reporter's draft.
A pull request (PR; GitLab calls it a merge request) asks to merge a branch into
main. It shows the full diff, lets teammates review and comment line by line, and runs automated tests (CI, CI/CD (coming soon)) before merging is allowed.Branch protection rules on GitHub enforce this:
maincan only change through an approved PR with passing tests.
Under the Hood#
1. git switch -c feature/quiz-timer branch off main
2. small commits Ch 2
3. git push -u origin feature/quiz-timer Ch 7
4. open a PR on GitHub describe what and why; link the ticket
5. CI runs tests; teammates review fix feedback with more commits
6. merge into main then delete the branch
7. main deploys automatically 05_DevOps_and_Cloud/01_DevOps/05_ci_cd.mdHow to merge a PR — three buttons on GitHub:
| Option | Result |
|---|---|
| Merge commit | keeps all branch commits + a merge commit (Ch 5) |
| Squash and merge | all the PR's commits become one commit on main — very common; tidy history, one commit per feature |
| Rebase and merge | replays the commits onto main, linear (Ch 6) |
Two team strategies you'll hear about:
Trunk-based development — very short-lived branches (hours to a couple of days), merged to
mainoften; unfinished features hidden behind feature flags (settings that switch code paths on or off at runtime). Used by most big tech companies; pairs with continuous deployment.GitFlow — long-lived
developandreleasebranches alongsidemain. Heavier; suited to software shipped in versions, rarely to web apps.
Being a good PR author: keep PRs small (a few hundred lines at most), describe why, and review your own diff before asking others. Being a good reviewer: check correctness, tests, readability and security; phrase comments as suggestions or questions.
Check yourself
4 questionsWhat is a pull request?
Show answerHide answer
A request to merge a branch into another (usually main), with the diff, discussion, review and automated checks.
What does "squash and merge" do?
Show answerHide answer
Combines all of the PR's commits into a single commit on the target branch.
Trunk-based development vs GitFlow — which uses short-lived branches?
Show answerHide answer
Trunk-based development.
Why keep PRs small?
Show answerHide answer
Small PRs are reviewed faster and more carefully, conflict less, and are easier to revert.