Skip to content

Try “polymorphism”, “TCP handshake” or “git rebase”.

    Computer Basics / Git

    Team Workflow: Branches, Pull Requests, Reviews

    main is the printed edition: always working, always deployable. Nobody commits to it directly.

    Chapter 8 of 113 min read

    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#

    • main is 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: main can only change through an approved PR with passing tests.

    Under the Hood#

    Output
      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.md

    How to merge a PR — three buttons on GitHub:

    OptionResult
    Merge commitkeeps all branch commits + a merge commit (Ch 5)
    Squash and mergeall the PR's commits become one commit on main — very common; tidy history, one commit per feature
    Rebase and mergereplays 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 main often; 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 develop and release branches alongside main. 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 questions
    1

    What is a pull request?

    Show answer

    A request to merge a branch into another (usually main), with the diff, discussion, review and automated checks.

    2

    What does "squash and merge" do?

    Show answer

    Combines all of the PR's commits into a single commit on the target branch.

    3

    Trunk-based development vs GitFlow — which uses short-lived branches?

    Show answer

    Trunk-based development.

    4

    Why keep PRs small?

    Show answer

    Small PRs are reviewed faster and more carefully, conflict less, and are easier to revert.