Pull Requests and Forks
Level 4 · Remotes and GitHub
How a pull request asks for a branch to be merged, and how a review catches bugs first. How a fork lets you offer a fix to a project you cannot change.
Course contentsLesson 11 of 13
Level 1 · Your first commits
Level 2 · Branches and merges
Level 3 · Undo and set aside
Level 4 · Remotes and GitHub
Level 5 · Working as a team
After this lesson you can
- Open a pull request that is easy to review
- Review someone else's change
- Offer a fix to an open-source project
13 mincovers 5 glossary entries
Worth reading first: GitHub, GitLab and Bitbucket
How a change gets reviewed before it joins main
A pull request asks for the commits on one branch to be merged into another, usually main. It is a page on the host that shows the changes, a note on what changed and why, and a thread for comments. Teammates read it, ask questions and approve it. Many teams need at least 1 approval before it can merge.
Code review is the reading part. Reviewers look for bugs, unclear names, missing tests and simpler ways to do the job. They can comment on a single line. You answer, push fixes to the same branch, and the pull request updates by itself. When everyone is happy, someone clicks merge.
Small pull requests get better reviews. A change of 50 lines gets read line by line. A change of 2,000 lines gets skimmed and approved, because nobody can hold it all in their head. Split big work into several pull requests, each doing one thing.
A good description saves the reviewer time. Say what the change does, why it is needed and how you tested it. Link the issue it fixes. A screenshot helps for anything you can see on the screen. A reviewer who has to guess the goal ends up checking the wrong thing.
Open-source software is code anyone can read, use and change, under a licence that says so. Most of it lives on GitHub. But you cannot push to a stranger's repo. Only the people the owner lets in can do that.
A fork solves this. It is your own copy of someone else's repo, made on the website and kept under your account. You can push to it freely. You clone your fork, make a branch, commit and push to your fork. Then you open a pull request from your fork back to the original.
The owner reviews it like any other pull request, and decides whether to merge it. Many projects say how they like to get changes in a file called CONTRIBUTING.md. Read it first. It often asks for tests, a style, or an issue opened before the work starts.
Fork and clone are easy to mix up. A fork is a copy on the website, under your account. A clone is a copy on your computer. Helping an open-source project usually takes both: fork it on the site, then clone your fork to work on it.
git clone https://github.com/jack/tool.git
cd tool
git switch -c fix-readme-typo
git commit -am "Fix a typo in the README"
git push -u origin fix-readme-typoWorked example
Jack fixes a typo in a big project
Jack spots a typo in the README of a free tool with 20,000 users. He forks it, clones his fork, fixes the one word and pushes.
He opens a pull request with a change of 1 line. A maintainer approves and merges it the next morning, and Jack's name joins the project's history.
The words for this lesson5
Check yourself
What is the difference between a fork and a clone?
Finished this lesson?
Marking it complete also marks its 5 glossary entries learned, which updates your roadmap and your saved page. 0 are already marked.