The Pull Request Workflow

The Pull Request Workflow in DevOps Tools: --- A scholarly journal receives far more manuscripts than it can print, and it receives most of them more than…


The Analogy: The Journal Submissions Desk and the Revision Letter

A scholarly journal receives far more manuscripts than it can print, and it receives most of them more than once. An author submits, referees respond, the author revises, and the revised paper comes back to the same desk. The person who sits at that desk is not a scientist. They are a submissions clerk, and their job is bookkeeping: every manuscript that arrives is logged against the version already on file, given a tracking number, and routed to the people who will judge it. The clerk never decides whether a paper is correct. They decide what the paper is being compared to, and that single clerical decision shapes everything that follows.

When a revised manuscript arrives, the clerk does not ask the referees to read the whole thing again from the first page. That would waste the referees on work they already did. Instead the author encloses a revision letter: a plain list of what changed since the copy the journal has on file, section by section, with the reasons. The referee reads that letter with the filed copy open beside the new one, and checks only the differences. The letter is not the paper and it is not the file copy. It is the gap between them, written down. A referee who trusts the letter can review a fifty-page paper in an afternoon, because the letter tells them the paper only changed in four places.

The referees return recommendations, never verdicts. One writes accept, one writes revise, one lists objections. The editor reads all three, weighs them against the journal's standards, and makes the single decision the whole process exists to produce: accept, request another revision, or reject. Only on accept does the paper leave the desk and enter the bound volume, the permanent numbered record that libraries keep forever. Everything before that moment -- the tracking number, the referee assignments, the revision letters, the correspondence -- lives in the journal's office files, not in the bound volume. The volume records the paper; the office records the argument about the paper.

The failure that ruins a review is not a bad referee. It is the clerk pulling the wrong file copy. Suppose two authors have papers open on adjacent topics, and a later revision of the neighbouring paper gets filed under the wrong number. Now the clerk lines the new manuscript up against a copy it never descended from. The referee, trusting the letter against the wrong baseline, sees paragraphs that appear to have changed but that this author never touched -- they belong to the neighbour's revision. The referee spends the afternoon objecting to edits the author did not make, and the author receives a review of a paper they did not write. Nothing was corrupted. The manuscripts are both intact. The clerk simply compared against the wrong reference point, and the entire review became noise.


Syntax or Core Structure

A pull request is not a git object. There is no commit, tree, or blob for it, and cloning a repository does not bring its pull requests with you -- they live in the forge (GitHub, GitLab, and the rest) as office records. A pull request is two references and a request to compare them: a base ref, the branch you want the work to land on, and a compare or head ref, the branch that carries the work. Everything a forge shows you about a pull request -- the commit list, the changed files, the "N commits ahead" badge -- is computed on demand from those two refs by the same ordinary commands you can run yourself.

The command that answers "what does this request contain" is the double-dot range. base..feature names every commit reachable from feature but not from base: exactly the work the branch introduces. It is asymmetric, and reversing it answers the opposite question -- how far the base has moved on without the branch.

# feature/rate-limit was branched from main; two commits were made on it.
# main, meanwhile, gained one commit of its own.

# how many commits would this PR introduce?
git rev-list --count main..feature/rate-limit
# how many commits has main gained since the branch forked?
git rev-list --count feature/rate-limit..main

# what commits does the PR carry, newest first?
git log --format='%s' main..feature/rate-limit

# where did the branch actually fork from?
git log --format='%s' -1 "$(git merge-base main feature/rate-limit)"

Output:

2
1
feat: reject requests over the limit
feat: add a rate limit setting
feat: add config module

The first number is the size of the request: two commits. The second is not a threat to those two commits -- it is simply how far main advanced while the branch was open, one commit. The commit list is those same two commits, and git merge-base names the commit both branches share, "feat: add config module", the fork point the whole comparison hangs from. A forge computes and displays all four of these the instant you open the request, and recomputes them on every push.


Technical Depth: What a Request Actually Compares

Two dots and three dots are not the same operator

Git overloads the dot notation, and the overload is the single most misread piece of the whole workflow. The same .. and ... mean different things to git log than they mean to git diff, and the difference is exactly the clerk's file-copy decision.

For git log and git rev-list, A..B is the set of commits reachable from B but not A, and A...B is the symmetric difference -- commits in one or the other but not both. For git diff, A..B compares the two branch tips directly, so it includes anything A itself changed after the fork. A...B compares the merge base of A and B against B, so it shows only what B changed relative to where it forked. That second form is what a forge's "Files changed" tab shows, and it is almost always the one a reviewer wants.

# two dots: diff the two branch tips against each other
git diff --name-only main..feature/rate-limit
echo '--'
# three dots: diff the merge base against feature only
git diff --name-only main...feature/rate-limit

Output:

README.md
config.py
server.py
--
config.py
server.py

The branch only ever touched config.py and server.py. The extra README.md in the two-dot list is not the branch's work at all -- it is a change main made after the fork, dragged in because two-dot diff compares tips and main's tip has moved. A reviewer reading the two-dot diff is the referee handed the wrong file copy: they see a file the author never opened.

Notationgit log / rev-listgit diff
A..Bcommits reachable from B but not Acompares the tip of A against the tip of B
A...Bcommits in A or B but not bothcompares the merge base of A and B against B

The fork point does not drift when the base moves

The merge base is a property of history, not of the current tips. When main gains commits that the branch never saw, the fork point stays exactly where it was, so the three-dot diff and the commit list stay stable. Only the "behind" count changes. Watch what happens after main takes two more commits of its own:

# main has now gained two further commits since the branch forked
git rev-list --count main..feature/rate-limit
git rev-list --count feature/rate-limit..main
git diff --name-only main...feature/rate-limit
git log --format='%s' -1 "$(git merge-base main feature/rate-limit)"

Output:

2
3
config.py
server.py
feat: add config module

The request is still two commits and still touches the same two files: that is the truth about the branch, and it did not move. The behind count rose from one to three because main moved, and the fork point is still "feat: add config module". This is why "your branch is 3 commits behind main" is a statement about main, not a defect in your work. The three-dot view is immune to it; the two-dot view is not.

The three doors on the merge button

When a maintainer clicks merge, the forge offers three strategies, and they produce genuinely different history. A merge commit (--no-ff) keeps every branch commit and adds one new commit with two parents, tying the two lines of history together. A squash (--squash) collapses the whole branch into a single new commit with one parent and no link back to the branch. A rebase replays the branch's commits onto the base with no merge commit at all. The parent count is the fingerprint that tells them apart:

# door one: a merge commit joins two histories
git merge --no-ff feature/cache -m 'Merge branch feature/cache into main'
echo "merge-parents=$(git cat-file -p HEAD | grep -c '^parent')"

# door two: a squash flattens the branch into one ordinary commit
git merge --squash -q feature/docs >/dev/null
git commit -q -m 'docs: add usage, config and cache sections'
echo "squash-parents=$(git cat-file -p HEAD | grep -c '^parent')"
echo "still-ahead=$(git rev-list --count feature/docs..main)"

Output:

merge-parents=2
squash-parents=1
still-ahead=1

The merge commit has two parents; the squash commit has one, the same as any everyday commit. The last line is the squash's hidden cost: feature/docs..main still counts one commit, meaning git considers the branch's own commits as never merged, because only their combined content landed, not the commits themselves. Merge that branch again by accident and git will happily replay the content a second time, since from its point of view the work was never integrated.


Real World Example: A Preview That Counts the Wrong Files

Before a forge exists, or when you want to see a request without opening a browser, it is natural to write a small script that prints what a pull request would contain. The one below takes a base and a feature branch and reports the fork point, the commit count both ways, the commits themselves, the files changed, and whether the merge would fast-forward. It is the kind of helper that ends up in a team's toolbox and gets trusted precisely because it looks like exactly what the forge shows.

#!/usr/bin/env bash
# pr-preview.sh <base> <feature> -- summarize the pull request <feature> would
# open against <base>, the way a forge does before you click "Create".
set -u

base=${1:?usage: pr-preview.sh <base> <feature>}
feature=${2:?usage: pr-preview.sh <base> <feature>}

fork=$(git merge-base "$base" "$feature")
ahead=$(git rev-list --count "$base".."$feature")
behind=$(git rev-list --count "$feature".."$base")

echo "base=$base feature=$feature"
echo "forked-at=$(git log --format='%s' -1 "$fork")"
echo "commits=$ahead base-ahead-by=$behind"

echo "-- commits in this PR:"
git log --format='  %s' "$base".."$feature"

echo "-- files changed:"
git diff --name-only "$base".."$feature" | sed 's/^/  /'

if git merge-base --is-ancestor "$base" "$feature"; then
  echo "merge=fast-forward"
else
  echo "merge=needs-merge-commit"
fi

Run against a freshly forked branch, it reads perfectly:

bash pr-preview.sh main feature/export

Output:

base=main feature=feature/export
forked-at=feat: base parser
commits=2 base-ahead-by=0
-- commits in this PR:
  test: cover the exporter
  feat: add CSV exporter
-- files changed:
  export.py
  test_export.py
merge=fast-forward

Two commits, two files, base zero commits ahead, and a clean fast-forward. Now let main gain two commits of its own -- a version bump and a changelog entry, touching VERSION and CHANGELOG -- and run the identical command again:

bash pr-preview.sh main feature/export

Output:

base=main feature=feature/export
forked-at=feat: base parser
commits=2 base-ahead-by=2
-- commits in this PR:
  test: cover the exporter
  feat: add CSV exporter
merge=needs-merge-commit
-- files changed:
  CHANGELOG
  VERSION
  export.py
  test_export.py

Three of the fields held their ground. The fork point is still "feat: base parser", the commit list is still the branch's own two commits, and base-ahead-by correctly rose to two. The merge verdict flipped to needs-merge-commit, which is honest: main is no longer an ancestor of the branch, so a fast-forward is impossible and a merge commit is required.

The files list is where the script lies. It now reports four files, and two of them -- CHANGELOG and VERSION -- were never touched by feature/export. They are main's own changes, and the reviewer who trusts this output will go looking for a changelog edit in a branch that never made one. The number of phantom files, two, is not a coincidence: it equals base-ahead-by, because those are precisely the files the base changed after the fork.

The design flaw is a single character. The files line uses git diff --name-only "$base".."$feature", the two-dot form that compares tips, when a pull request is defined by the three-dot form that compares against the merge base. Changing .. to ... on that one line fixes it completely and permanently, and the bug is invisible until the base moves -- every test on a freshly forked branch passes, which is exactly why it survives into a team's toolbox. Two smaller gaps sit alongside it. The merge=fast-forward check only tells you the merge will not need a commit; it says nothing about whether the three-way merge will hit a conflict, so a "needs-merge-commit" verdict is not a warning and a clean verdict is not a guarantee. And the script never checks that base and feature name real branches, so a typo surfaces as a raw git merge-base error deep in the output rather than a usage message at the top.


Common Mistakes

  1. Reviewing with the two-dot diff. Reading base..feature shows you the branch's changes plus everything the base changed after the fork. On a long-lived base that is a pile of unrelated files. The forge uses three-dot for its diff tab; match it, or you will review the wrong file copy.
  1. Reading "N commits behind" as lost work. The behind count is feature..base: how far the base moved, not damage to your commits. A branch can be a hundred behind and still contain every one of its own commits intact. Behind measures the base, not your branch.
  1. Believing a pull request is a git object. It is forge metadata -- a base ref, a head ref, and a conversation. Cloning the repository does not bring it, git log does not show it, and deleting the branch on the forge can close it. Nothing about it lives in the object database.
  1. Force-pushing after a rebase mid-review. Rebasing rewrites commit ids, and reviewers' inline comments are anchored to the old ids. A force-push mid-review orphans every comment, because the lines they were attached to now live on commits that no longer exist.
  1. Opening the request against the wrong base. Target the wrong branch and the diff fills with commits the base is missing, because the merge base is far back. The request looks enormous and unreviewable. The fix is choosing the base whose merge base with your branch is recent, not the newest branch.
  1. Confusing --squash with --no-ff. A no-ff merge keeps your commits and adds a two-parent commit; a squash flattens them into one commit with a single parent and no link back. Squash discards the branch's individual history. Pick deliberately, not by whichever button is default.
  1. Reading "needs-merge-commit" as "will conflict". Divergence forces a merge commit but says nothing about conflicts. Two branches can diverge across a hundred commits and merge without a single conflict if they never touched the same lines. The merge-commit requirement and the conflict risk are independent facts.
  1. Merging before checks finish reporting. A green forge page can mean "checks passed" or "checks have not started". Merging on the second is merging untested code that happened to have a green checkmark for an unrelated reason. Require the checks, do not eyeball them.
  1. Letting a branch sit open for weeks. The diff against base stays correct, but every commit the base takes is one more chance for a future conflict, and reviewers lose the context they had when the work was fresh. A stale branch is not wrong; it is just increasingly expensive to land.

Best Practices

  • Open the pull request early as a draft. A draft runs CI and collects feedback without inviting a merge, so problems surface while the branch is small instead of after it has grown for a week.
  • Keep branches short-lived and rebase them onto the base often. A branch that forked yesterday has a recent merge base, a small three-dot diff, and almost nothing to conflict with.
  • Review with the three-dot diff, always. It is what the forge shows and it is the only view that isolates the branch's own work from whatever the base did in the meantime.
  • Write the description as a revision letter: what changed, why, and what you deliberately left out. Reviewers who know your intent review the gap, not the whole paper.
  • Make the required checks actually required in branch protection. A check that can be skipped is documentation, not a gate, and the one time it matters is the time someone skips it.
  • Choose the merge strategy to match what the commits mean. Squash a branch of "wip" and "fix typo" commits into one; preserve a branch whose individual commits each tell a real story.
  • Link the issue with a closing keyword such as "Fixes #402" so the merge closes the ticket automatically and the history records why the change existed, not just what it changed.
  • Never force-push a shared base branch, and avoid force-pushing a branch under active review. Rewriting published history orphans comments and forces every collaborator to recover by hand.

Practice Exercises

  1. Reproduce the phantom files. Fork a branch from main, change one file on it, then add two unrelated commits to main that touch two other files. Run git diff --name-only main..yourbranch and git diff --name-only main...yourbranch and explain, in terms of the merge base, why the two lists differ and which one a reviewer should read.
  1. Fix the preview script. Take pr-preview.sh from the example, change the files line from two dots to three, add a check that both refs exist before comparing them, and report whether a test merge succeeds rather than only whether it fast-forwards. Rerun the base-moved scenario and confirm the files list now shows exactly the branch's own files.
  1. Fingerprint the merge doors. Build a branch with three commits, then merge it into main twice in separate clones: once with --no-ff and once with --squash. Report the parent count of the resulting commit and the branch..main count each way, and say which strategy leaves the branch counted as unmerged and why.
  1. Measure a stale branch. Fork a branch, then advance main by several commits without touching the branch. Report the ahead and behind counts and the merge-base subject. Rebase the branch onto main, then report all three again and explain why ahead is unchanged, behind is now zero, and the merge base moved forward.