ΟδηγοίΓια προγραμματιστές
Pull requests
How a change gets from a branch into main: opening a pull request, review, automated checks, and the ways GitHub can merge it.
Η σελίδα δεν έχει μεταφραστεί ακόμη, γι' αυτό εμφανίζεται στα αγγλικά.
What a pull request is
A pull request (a "PR") is a proposal on GitHub to merge one branch into another, almost always your branch into main. It is not a git command; it is a page wrapped around a merge that has not happened yet.
That page shows the difference between the two branches (the "diff"), holds the conversation about it, and runs the automated checks. Nothing reaches main until someone presses Merge.
Opening one
- Push your branch:
git push -u origin feat/patient-export. - GitHub offers a "Compare & pull request" button for a freshly pushed branch. Or open the repository’s Pull requests tab and choose New pull request.
- Check the two branches at the top: the base is where the change goes (
main), the compare is your branch. - Write a title that says what the change does, and a description of what a reader would see before and after.
Not ready for review yet? Open it as a draft. A draft runs the checks and can be discussed, but cannot be merged until you mark it ready.
Automated checks
Every push to a PR starts the project’s CI (continuous integration): a clean machine installs the project and runs its checks. A typical setup looks like this:
npm ci # install exactly what the lockfile says
npm run lint # style and common mistakes
npm run build # does it compile?
npm test # do the tests pass?A red check means one of those failed. Open its log from the PR’s Checks tab, fix the cause on your branch and push again.
Review
A reviewer reads the diff and can leave comments on single lines. When they finish they submit one of three verdicts:
- Comment
- Questions or remarks, no verdict.
- Approve
- The change is good to merge.
- Request changes
- Something must change before it can be merged.
Answer each comment, either with a commit that addresses it or a reply saying why not, and mark the conversation resolved. Then ask for another look.
Keeping a PR up to date
While your PR is open, other PRs merge into main. If they touched the same lines, GitHub reports a conflict and blocks the merge. Bring main into your branch, resolve the conflict as on the Git basics page, and push:
git switch feat/patient-export
git pull origin main # merges main into your branch
# resolve any conflicts, then
git pushmainStartfeat/exportExport as PDF- Someone else’s pull request
- Merge
maininto the branch - Fix the conflict
- Merge pull request
main is merged into the branch, the conflict is fixed there, and only then does the branch merge into main.How GitHub merges
The green Merge button has three modes. The repository decides which are allowed:
- Create a merge commit
- Keeps every commit from the branch and adds a merge commit on
main. The full story stays in the history. - Squash and merge
- Folds the whole branch into one commit on
main. Tidy, but the individual commits are gone frommain’s history. - Rebase and merge
- Replays each commit on top of
mainone by one, with no merge commit. A straight line, with every commit kept.
mainStartfeat/exportDraft the export- Add tests
- Review fixes
- Merge pull request
main by one merge commit.mainStart- Export as PDFthree commits in one
main as a single one.mainStart- Draft the export
- Add tests
- Review fixes
main one after another, with no merge commit.After the merge, delete the branch (GitHub offers a button) and update your local main with git switch main && git pull.
Words you will meet
HEAD- The commit you currently have checked out, usually the tip of your current branch.
origin- The default name of the remote you cloned from.
- Upstream
- The remote branch your local branch pushes to and pulls from.
- Fork
- Your own copy of someone else’s repository on GitHub, for proposing changes without write access.
- Rebase
- Moving a branch’s commits so they start from a newer commit. Rewrites those commits.
- Cherry-pick
- Copying a single commit from one branch onto another.
- Tag
- A fixed name for one commit, often a release such as
v1.2.0.