This chapter follows Advanced Git.
A pull request (GitHub) or merge request (GitLab) is a proposal: “merge these commits from my branch into yours.” Underneath, it is still Git objects and refs—plus permissions, discussion, and checks on the host.
Without GitHub: patches and request-pull
Open-source projects predating hosts often used email:
git format-patch main --stdout > series.patchgit send-email --to=list@example.org series.patchOn the maintainer side:
git am < series.patchgit request-pull generates a summary maintainer can use to pull your branch from your public repo URL:
git request-pull main https://example.com/you/project.git feature/loginThese flows still work for air-gapped or self-hosted workflows. Code review happens on mailing lists or chat instead of inline threads.
Forks versus branches on one repo
Same repository, feature branch: teammates with write access push feature/x, open a PR into main. Common for small teams.
Fork: you clone yourname/project, push there, open a PR yourname:feature → org:main. Required for drive-by contributors without write access. Sync the fork by fetching upstream and merging or rebasing.
git remote add upstream https://github.com/org/project.gitgit fetch upstreamgit switch maingit merge upstream/maingit push origin mainPull request lifecycle on GitHub
- Create a branch locally; commit;
git push -u origin feature/x. - Open a PR on GitHub (or
gh pr create). - CI runs (see GitHub Actions).
- Reviewers comment; you push fixes to the same branch—the PR updates.
- Maintainer merges when checks and approvals pass.
gh pr create --fillgh pr checkout 42gh pr review --approvegh pr merge --squashMerge button choices
GitHub offers three strategies—same concepts as Merging versus rebasing:
| Option | Effect |
|---|---|
| Create a merge commit | Preserves branch topology with a merge node |
| Squash and merge | One commit on the base branch |
| Rebase and merge | Linear history on base; rebased commits |
Team policy picks one default; protect main so only PR merges land.
Branch protection and CODEOWNERS
Branch protection rules can require:
- Pull request before merge
- Approving reviews
- Passing status checks
- Linear history (disallow merge commits)
CODEOWNERS (.github/CODEOWNERS) auto-requests review from paths’ owners:
* @org/core-team/src/payments/ @org/paymentsProtection applies on the server; local Git does not enforce it.
Draft pull requests and linked issues
Draft PRs signal work in progress—CI may still run, but reviewers know not to merge. Closing keywords in PR descriptions (Fixes #123) link issues and can auto-close on merge.
When to prefer plain Git merge locally
Not every team uses PR UI. Maintainers may git fetch a contributor branch and git merge locally after review—functionally a PR without the web thread. Document whichever workflow your org uses.
Next: Collaborating with Git.
Check your understanding
Question 1 of 7
0 of 7 checked