Sub topic 1
Why a busy main branch breaks with green pull requests
Prerequisites
This chapter assumes you already know:
- Basic Git branching and merging.
- How pull requests and code review work on GitHub.
- How branch protection rules or repository rulesets require status checks.
- GitHub Actions workflow syntax, including the
pull_requesttrigger.
Green checks describe a past state
A required status check reports on one specific commit. For a workflow triggered by pull_request, that commit is a test merge of your branch with the base branch as it was when the check started. If main moves afterward, the result is not recomputed. The green checkmark says "this branch was fine against the main of an hour ago", not "this branch is fine against main now".
On a quiet repository the difference rarely matters. On a busy one, several pull requests are open and approved at once, and each was tested against a different version of main.
A semantic conflict that Git cannot see
Git only detects textual conflicts, where two changes touch the same lines. Two changes can touch different files and still break each other.
Suppose main contains this module:
# config.py
def parse_config(text):
return dict(line.split("=", 1) for line in text.splitlines())Pull request A renames the function to load_config and updates every caller it can find. Pull request B, opened earlier, adds a new file that calls parse_config. Each pull request passes its own tests because neither one sees the other's change. Git merges both without a conflict, because they edit different files. After the second merge, main fails with an ImportError or NameError.
Nobody did anything wrong by the rules. The process allowed a merge whose result was never tested.
The first fix: require up-to-date branches
Branch protection offers "Require branches to be up to date before merging". With it, a pull request cannot merge until it contains the latest main. In the example, B would have to merge main (including A's rename), rerun its checks, and fail before it could land.
This is correct, but it does not scale. Only one pull request can merge per round. Every other approved pull request becomes out of date and must update its branch and wait for CI again. With N ready pull requests, CI work grows roughly with N², and authors spend time clicking "Update branch" and watching builds.
What you actually need
You want a way to test each pull request against the exact commit it will become part of: the latest main plus everything already approved ahead of it. You also want the system, not the author, to build that combination and merge it in order.
| Approach | Tests the real merge result? | Author effort | Throughput on a busy branch |
|---|---|---|---|
| Checks on the pull request only | No, only against an old base | Low | High, but `main` can break |
| Require up-to-date branches | Yes | High, manual updates | Low, one at a time |
| Merge queue | Yes | Low | Good, builds run in parallel |
A merge queue is GitHub's built-in version of that last approach. The next chapter describes how it works.
Exercise
Two approved pull requests each pass all required checks and touch different files. Why can merging both still leave main failing, and why does "require branches to be up to date" prevent it?
Show answer
Each pull request was tested against an older version of main that did not include the other's changes, so the combination was never tested. Git sees no textual conflict, so it merges both. Requiring up-to-date branches forces the second pull request to include the first one's changes and rerun its checks before merging, so the failure shows up on the pull request instead of on main.