Open Your First Pull Request

Your format-and-lint branch holds four commits that answer the first issue: Prettier’s setup, the reformat, ESLint’s setup, and the two fixes. So far, they only exist on your laptop, though, and the README’s To do section says that every change now goes into main through a pull request.

In this lesson, you’ll push the branch to GitHub and open your first pull request. You’ll write a description that tells a reviewer what changes and why, and link the pull request to the issue so that the issue closes by itself once the work is merged. Start by getting the branch onto GitHub, where pull requests live.

Push the Branch to GitHub

Until now, you merged branches on your own computer and pushed main. On a team, main is the branch everyone builds on and the site is published from, so a change shouldn’t land there before someone has read it. A pull request is a proposal to merge one branch into another. It shows the change, says what it’s for, and holds the discussion about it until someone merges it.

Even when you work alone, the proposal gives you another chance to read the whole change carefully and a record that connects the code to the issue that asked for it. Your pull requests are public, too, so employers can see how you work. How to Become a Frontend Developer explains why they look. Teams call this kind of read-through a review, and you’ll do your first one later in this course.

Pull requests aren’t part of Git, which only gives you the branch and the merge. They’re a feature of the hosting service, so you open one on GitHub’s website.

GitLab calls the same thing a merge request. Some tutorials use gh pr create from GitHub’s optional command-line tool, GitHub CLI, but this course uses the website, which shows you every part of the pull request.

That’s why the first step is a push, because GitHub can only show a branch it has. Before you push, look at exactly which commits are about to leave your laptop:

Language: Shell
$ git log --oneline main..format-and-lint
a06a7b2 Fix the two problems ESLint found in closing-soon.js
7147a6a Add ESLint with the recommended rules
227d527 Format the whole project with Prettier
6510c28 Add Prettier, pinned to one version

The range main..format-and-lint lists the commits on the branch that main doesn’t have. These are your four commits, and your hashes will differ. You read each staged diff and looked for keys before you committed, so these four are ready to go. Push the branch the same way you set up main. The -u option makes Git remember where this branch belongs on GitHub:

Language: Shell
$ git push -u origin format-and-lint
Enumerating objects: 39, done.
Counting objects: 100% (39/39), done.
Delta compression using up to 8 threads
Compressing objects: 100% (23/23), done.
Writing objects: 100% (28/28), 20.16 KiB | 3.95 MiB/s, done.
Total 28 (delta 18), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (18/18), completed with 9 local objects.
remote:
remote: Create a pull request for 'format-and-lint' on GitHub by visiting:
remote:      https://github.com/.../generic-grocery/pull/new/format-and-lint
remote:
To https://github.com/generic-grocery-dev/generic-grocery.git
 * [new branch]      format-and-lint -> format-and-lint
branch 'format-and-lint' set up to track 'origin/format-and-lint'.

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Become a Member to join the conversation.