GitHub Pull Requests: How and Why to Use Pull Requests

Become a PR pro in about 5 minutes.
John John (304)
5 minutes

At howchoo, our code is on private Github repos. We've recently started using pull requests to submit new changes to the code base. Likewise, we've been using Github issues for a while to keep track of bug fixes and small tasks. Our workflow has been improved significantly due to a few hidden gems in Github. In this guide, I'll show how to make pull requests as well as a few other workflow tips.

Posted in these interests:
h/webdev60 guides
h/code69 guides
GitHub
h/github8 guides
Finding the pull requests

When viewing a repository in your Github account, you should see an icon with the words "Pull requests". Fitting, right? Click on that link to go to the pull request page.

Click "New pull request"

The pull requests page will show you existing, open pull requests. You'll find a button at the top that says "New pull request". Click that one.

Choose your branches

At this point you'll choose your branches, on the left the branch you're merging into and on the right the branch you're merging from. At this point, it's assumed that you've pushed your branch to origin. The branch you're merging into is often master or depending on your branching model it could be called develop. When this pull request is closed, the compare branch will be merged into the base branch.

Create the pull request

Once you've selected your branches, click "Create pull request". This won't create it but will give you the chance to leave a comment. It's a good idea to leave a descriptive comment about what changes will be merged. It is assumed that another developer will be reviewing these changes so comments are helpful. At this point, you can scroll down to see a diff of the files changed. This is a good time to do a final review of your code to make sure it's ready to be merged. Now click "Create pull request" again to actually create the request.

Pull requests are a great way to review code. Once you've created the pull request you can send the url to someone else in the organization. They will be able to see the diff, leave comments, and eventually close and merge the pull request if everything looks good.

Wouldn't it be cool if Github would automatically close issues with a pull request? Well, they do! Before submitting the pull request, you should use the following language in a commit message:

Fixes #167
where 167 is the issue number this branch should close. By typing this in the commit message, issue number 167 will automatically be closed when the branch is merged into master. There are a number of different phrases you can write in the commit message to force the issue to be closed. A full list can be found here - Closing issues via commit messages.

GitHub Codespaces is officially in beta.
Ash Ash (362)
0

Earlier this week, GitHub announced the launch of a new cloud-hosted IDE known as GitHub Codespaces. This new service is a full development environment based on Microsoft's Visual Studio Code.