Key idea
GitHub keeps a shared copy of your repository. You push a branch to it, then open a pull request: a request to merge that branch into main, with a description, the diff and the results of automated checks on one page, where others can review it before it lands.
Your repository has a remote
In module 5 your commits and branches lived on your machine. A remote is another copy of the same repository, usually on GitHub, that everyone on the team pushes to and pulls from. When you clone a repository, Git names the copy you cloned from origin.
git remote -v # where origin points
git push -u origin add-search # send your branch to GitHub
-u links your local branch to the one on GitHub, so from then on a plain git push is enough.
Signing in to GitHub to push
GitHub doesn't accept your account password for git push. The simplest way in is the GitHub CLI: install gh, run gh auth login, and choose HTTPS; it sets Git up to push as you. The alternative is a personal access token, pasted when Git asks for a password. Check the current steps in GitHub's docs, at docs.github.com under "Authenticating with GitHub from Git".
Clone or fork?
- Clone when you can push to the repository: your own, or your team's. You get a local copy; your branches go back to the same repository.
- Fork when you can't: someone else's project, or a sample. A fork is your own copy of the repository under your GitHub account. You push to your fork and open pull requests from it.
You'll fork a sample in the next-but-one lesson, and again in Path 5 to deploy from it.
The parts of a pull request
When you push a branch, GitHub offers to open a pull request for it. The page you get has four parts that matter:
- Title. What the change does, in a few words: "Add search to the task list", not "Fixes".
- Description. Why the change is needed, what it does, and how you checked it. The reviewer reads this before the code.
- The diff. The Files changed tab shows every line added and removed, compared with the branch you're merging into.
- Checks. Automated jobs the repository sets up, such as tests, that run on every push to the branch and report a pass or a fail on the page. Lesson 2.7.4 shows where they come from.
The branch you merge into is the base (usually main); the branch with your work is the compare branch.
A description worth reading
A reviewer can't ask you what you meant at 11pm. Give them what they need up front:
## Why
Users with many tasks can't find one quickly.
## What
Adds a search box to the task list. Matching is case-insensitive.
No new dependencies.
## How I checked
npm test passes. Searched for "milk" and "MILK" locally: both find "Buy milk".
Keep one change per pull request. A pull request that adds search and also renames every file is two reviews squeezed into one, and the second one hides the first.
Draft pull requests
If you want early feedback on unfinished work, open it as a draft: next to Create pull request, open the dropdown and choose Create Draft Pull Request. A draft can't be merged until you mark it ready for review.
Check yourself