Skip to content
Tech Atlas, home
Search
Esc
  • All roadmapsBrowse every learning path
  • ExploreFind a technology area
  • ProjectsGuided projects and builds
  • My AtlasYour learning dashboard
Lesson 4 of 6 · Concept · 20 min · revision 3

Pull requests, reviews and short-lived branches

Deliver a change to a protected `main` through a pull request: push a short-lived branch, pass review and required checks, merge, and tag the release.

Contentsand lesson path

What you will learn

  • Deliver a change through a pull request on a protected main branch, including review, required checks and a tagged release.

01. Why it matters

On a team, main is the branch everyone builds on and, often, the one that gets deployed. If anyone can push anything to it, one untested change can block the whole team or break production. A pull request (PR; GitLab calls it a merge request) puts a gate in front of main: your branch is proposed, discussed, tested and approved before it is merged.

This lesson follows one small change from your laptop to a tagged release on GitHub. The ideas carry over to GitLab, Bitbucket or Azure DevOps.

02. Remotes: your copy and the shared copy

Every clone is a complete repository. The shared one, usually on GitHub, is just another repository that your clone knows as a remote, conventionally named origin. Git only talks to it when you ask:

  • git fetch downloads new commits and updates remote-tracking branches such as origin/main, your local record of where the remote's branches were at the last fetch
  • git pull runs git fetch, then brings the upstream branch into your current branch: a fast-forward when you have no commits of your own; otherwise Git asks you to choose between merging (--no-rebase) and rebasing (--rebase), or to set pull.rebase once in your config
  • git push uploads your commits and moves the matching branch on the remote

In the sessions below, origin is a local practice repository standing in for GitHub, so its path is shortened to .... When you push a new branch to GitHub, the output also includes a remote: message with a link for opening a pull request.

Terminal · publishing a short-lived branch
$ git switch -c add-rate-limit
Switched to a new branch 'add-rate-limit'
$ echo 'limit: 100 requests per minute' > api.conf
$ git commit -qam 'Add a per-client rate limit'
$ git push -u origin add-rate-limit
To .../pr-demo/origin.git
 * [new branch]      add-rate-limit -> add-rate-limit
branch 'add-rate-limit' set up to track 'origin/add-rate-limit'.
$ git branch -vv
* add-rate-limit b9dc832 [origin/add-rate-limit] Add a per-client rate limit
  main           5464a17 [origin/main] Add API config

-u (short for --set-upstream) links your branch to origin/add-rate-limit. From then on a plain git push or git pull knows where to go, and git status can tell you whether you are ahead of or behind the remote. git branch -vv shows each branch's upstream in square brackets.

03. The life of a pull request

A typical flow on GitHub:

  1. Start from an up-to-date main: git switch main, git pull, then git switch -c <short-descriptive-name>.
  2. Make small, focused commits and push the branch.
  3. Open the pull request against main. The title says what the change does; the description says why, how you tested it and what is risky, and links the issue ("Closes #87" closes it when the PR is merged). Open it as a draft for early feedback.
  4. Automated checks run. A CI workflow builds the code, runs tests and linters, and reports a status on the pull request.
  5. Review. Reviewers read the diff, leave comments on specific lines, and submit a review that comments, approves or requests changes.
  6. Address feedback by committing on the same branch and pushing again. A pull request follows its branch, so the new commits appear in it automatically and the checks run again. Reply to each comment, then re-request review.
  7. Merge once the approvals and checks are in place, and delete the branch. GitHub offers three methods: a merge commit, squash and merge (the PR's commits become one commit on main) and rebase and merge (the commits are replayed onto main with no merge commit). Teams usually pick one and stick to it.
  8. Update your clone: switch to main and git pull to get the merged result.
Terminal · answering a review comment, then syncing after the merge
$ echo '# Raise only after load testing' >> api.conf
$ git commit -qam 'Explain when the limit may be raised'
$ git push
To .../pr-demo/origin.git
   b9dc832..a056cf6  add-rate-limit -> add-rate-limit
$ git switch main
Switched to branch 'main'
Your branch is up to date with 'origin/main'.
$ git pull
From .../pr-demo/origin
   5464a17..2cba632  main       -> origin/main
Updating 5464a17..2cba632
Fast-forward
 api.conf | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
$ git branch -d add-rate-limit
Deleted branch add-rate-limit (was a056cf6).

Notice that git switch main reported the branch as up to date even though the pull request had already been merged. That message compares main with origin/main as of your last fetch; only git pull, which fetches first, discovered the merge. When in doubt, fetch.

Review works best as a conversation about the change rather than a hurdle to get past:

  • As the author, keep the pull request small enough to review in one sitting, read your own diff on GitHub before asking anyone else, and say in the description what kind of feedback you want.
  • As a reviewer, check behaviour first (does it do what the description says, is it tested, what could break), then readability. Be specific, explain your reasoning, and label optional suggestions as such; many teams prefix them with "nit:".
  • For both, answer every comment, even with a short "done", and take long debates to a call.

04. Protecting main

The flow above is only a convention until the hosting platform enforces it. On GitHub you protect main with a branch protection rule or a ruleset in the repository settings. The settings teams reach for first:

  • Require a pull request before merging, with a number of required approvals (one is a common start). Direct pushes to main are then rejected, and because authors can never approve their own pull requests, the approval has to come from someone else.
  • Dismiss stale approvals when new commits are pushed, so an approval always covers the code that is actually merged.
  • Require review from code owners: a CODEOWNERS file maps paths to the people or teams who must approve changes to them.
  • Require status checks to pass: name the CI jobs that must succeed. You can also require the branch to be up to date with main, so the checks ran against what will really be merged.
  • Require conversation resolution, so review comments cannot simply be ignored.
  • Block force pushes and deletions of main.

Apply the rules to administrators too (GitHub calls this "Do not allow bypassing the above settings"), or someone in a hurry will skip them. Then everyone can trust that whatever is on main was reviewed and passed the checks, which is what makes frequent merging safe.

A required check needs a check to require. On GitHub that is usually a job in a GitHub Actions workflow, a YAML file under .github/workflows/. This minimal workflow runs on every pull request and every push to main, and its job id, test, becomes the name of the check. The checkout action is pinned to a full commit SHA, with its tag in a comment, because a tag can later be moved to other code:

YAML · .github/workflows/ci.yml (checkout v7.0.1, checked with actionlint 1.7.12)
name: ci
on:
  pull_request:
  push:
    branches: [main]
permissions:
  contents: read
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
      - run: sh run-tests.sh # replace with your own test or lint command
Shell · run-tests.sh, a stand-in test for the practice repository
#!/bin/sh
# Fails when api.conf no longer sets a limit; replace it with your real tests.
grep -q '^limit:' api.conf

Push both files to main before you protect the branch. GitHub offers only checks it has seen: its documentation says a required status check must have completed successfully in the repository during the past seven days. So open one pull request, let test run, then add test under Require status checks to pass. From then on, a pull request whose test job fails cannot be merged; try it with a branch that deletes the limit: line.

Keep job names unique across workflows, since duplicates make the required check ambiguous, and put no paths or branches filter on the pull_request trigger of a required workflow: a skipped workflow leaves its check pending, which blocks the merge. The continuous integration lab builds a full pipeline.

05. Short-lived branches and trunk-based development

How long should a branch live? The longer it lives, the further it drifts from main: more conflicts, bigger reviews and a late surprise when everything finally meets. Trunk-based development answers with a simple rule: everyone integrates into one shared branch (the trunk, here main) at least once a day. Teams that use pull requests do this with short-lived feature branches that last hours, or a day or two at most, each carrying one small change.

Two techniques make that work for features that take longer than a day:

  • Feature flags: merge the code early but switched off, and turn it on when the whole feature is ready. Unfinished work lives on main without reaching users.
  • Slicing: split a feature into steps that are each safe to ship, such as adding a database column, then the code that writes it, then the screen that reads it.

Some teams keep long-lived develop and release branches instead. That can suit software shipped in infrequent versions, but every merge between them is bigger and riskier.

06. Tagging a release

When main reaches a state you want to ship, give that exact commit a permanent name with a tag. Use an annotated tag for releases. A lightweight tag is only a name pointing at a commit; an annotated tag is an object of its own that records who created it, when, and a message, and it can be signed.

Most teams name releases with semantic versioning, MAJOR.MINOR.PATCH:

  • increase PATCH (1.4.2 → 1.4.3) for backwards-compatible bug fixes
  • increase MINOR (1.4.3 → 1.5.0) for new features that keep existing behaviour working; PATCH goes back to 0
  • increase MAJOR (1.5.0 → 2.0.0) for changes that break existing users; MINOR and PATCH go back to 0

Tag the merge commit on an up-to-date main, then push the tag explicitly, because git push does not send tags unless you ask.

Terminal · an annotated release tag
$ git tag -a v1.0.0 -m 'Rate limiting for all clients'
$ git push origin v1.0.0
To .../pr-demo/origin.git
 * [new tag]         v1.0.0 -> v1.0.0
$ git show --no-patch v1.0.0
tag v1.0.0
Tagger: Ada Learner <[email protected]>
Date:   Sat Oct 17 13:48:11 2026 +0000

Rate limiting for all clients

commit 2cba63217948e3d799b9bcac9e91a277b0ef411d (HEAD -> main, tag: v1.0.0, origin/main)
Merge: 5464a17 a056cf6
Author: Sam Maintainer <[email protected]>
Date:   Sat Oct 17 13:48:11 2026 +0000

    Merge pull request #12 from example/add-rate-limit

The first block is the tag object (tagger, date, message); below it is the commit it names, here the merge commit of the pull request. On GitHub, a release is built on a tag: it adds release notes, which GitHub can generate from the merged pull requests, and optional downloadable files.

Treat release tags as permanent. If v1.0.0 turns out to be broken, fix forward and release v1.0.1 rather than moving the tag, because others may already have built or deployed it.

07. Check your understanding

Practice check · 3 questions

Delivering a change

Apply the workflow from this lesson to each situation.

Q1. You create the annotated tag `v1.2.0` on `main` and run `git push`. A teammate fetches, but `git tag` in their clone does not list `v1.2.0`. Why?
Q2. A reviewer requests changes on your open pull request. How do you update it?
Q3. Your team integrates into `main` every day, but one feature will take two weeks. How do you keep merging without exposing half-finished work to users?
Practice only: not graded, not saved, not evidence.

08. Apply it

This is the core of the skill's practice project. Use a public, secret-free repository on GitHub, your own or one shared with a study partner: GitHub Free protects branches only in public repositories.

  1. Add ci.yml and run-tests.sh (or your real test command), push them to main, and open one pull request so the test check runs. Then protect main: require a pull request with one approval and the test status check.
  2. Create a short-lived branch, make two or three focused commits, and open a pull request whose description covers what, why and how you tested it.
  3. Ask your partner to review and leave at least one comment. Address it with a new commit on the same branch and push.
  4. Merge once approved and green, delete the branch, pull main, tag the merge commit as v0.1.0 with an annotated tag, push the tag and create a GitHub release from it.

Working alone? GitHub does not let you approve your own pull request, so set the required approvals to zero (keep the status check) and review your own diff carefully before merging.

09. Review prompt

Without looking back, list the steps from git switch -c to a published release, naming the command or GitHub action for each. Then explain to a teammate which branch protection settings you would switch on first for a new service, and why. Finally, explain why a new CI job cannot be made a required check until it has run.

References

Your progress

Reading state

Sign in to save that you finished reading this lesson.

Sign in to mark reading complete

Prove this skill

8 questions · about 6 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.
Take the skill check