pull-request-tutorial-for-students

A Visual Guide to Pull Requests for my students. The simple way 😊


Project maintained by michalczukm Hosted on GitHub Pages — Theme by mattgraham

Pull Request Tutorial

This tutorial is fork 🍴 from github.com/yangsu/pull-request-tutorial

Send πŸ’™ there 😊

I rephrased some points, add few, remove few and added fresh screens from GitHub.


Pull Request = PR

This tutorial is written both for:

All sections are marked according to which role is making this part.

Table of contents

What is a Pull Request? πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»/πŸ“–

From Github’s Using Pull Requests Page

Pull requests let you tell others about changes you’ve pushed to a GitHub repository. Once a pull request is sent, interested parties can review the set of changes, discuss potential modifications, and even push follow-up commits if necessary.

Pull Requests are commonly used by teams and organizations collaborating using the Shared Repository Model, where everyone shares a single repository and topic branches are used to develop features and isolate changes. Many open source projects on Github use pull requests to manage changes from contributors as they are useful in providing a way to notify project maintainers about changes one has made and in initiating code review and general discussion about a set of changes before being merged into the main branch.

Here’s an example pull request from jQuery’s github repo.


Creating a Pull Request πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

There are 2 main work flows when dealing with pull requests:

  1. Pull Request from a branch within a repository
  2. Pull Request from a forked repository (this article is not about this flow)

Here we are going to focus on 1.

πŸ‘‰ PR from this example: https://github.com/michalczukm/pull-request-tutorial-for-students/pull/1

Creating a Topical Branch

First, we will need to create a branch from the latest commit on master (or develop, depends on git flow you’re using).

Make sure your repository is up to date first using

git pull origin master

Note: git pull does a git fetch followed by a git merge to update the local repo with the remote repo. For a more detailed explanation, see this stackoverflow post.

To create a branch, use git checkout -b <new-branch-name> [<base-branch-name>], where base-branch-name is optional and defaults to master. I’m going to create a new branch called pull-request-demo from the master branch and push it to github.

git checkout -b pull-request-demo
git push origin pull-request-demo

Creating a Pull Request

To create a pull request, you must have changes committed to your new branch.

Go to the repository page on github. And click on β€œPull Request” button in the repo header.

Pull Request Button

Select branches:

Select branches

Enter meaningful title and description for your pull request (other people will be reading this, not machines!).

Remember you can use Github Flavored Markdown in the description and comments.

Title and Description

Finally, click on the green β€œCreate pull request” button to finish creating the pull request.

You should now see an open pull request.

Which might be ready for merge (doesn’t make sense, without code review :exclamation: No way :exclamation:) - depending on your GitHub repository settings.

PR ready to merge

Or with constraints, like Review reqired (thats how we do it :blush:)

PR with constraints

Great :clap:

Now its time for reviewers πŸ“– to take a look at your PR. I hope you already added them - to they get notified!

From now on this PR is your platform for communication about this code changes.

You can:

Updating a Pull Request πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

:wave: you, PR creator, yes you :exclamation:

Since pull request is a request to add commit from one stream (branch) to another, the simplest way to update code in your PR is to … push new commits on your branch.

# add changes, improvements, make your PR better
...

# then commit it
git commit -m "meaningful message describing your changes"

# and push it
git push origin pull-request-demo

Using a Pull Request πŸ“–

So, you received a PR. What next :question:


Merging a Pull Request πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Once you and your collaborators are happy with the changes, you start to merge the changes back to master. There are a few ways to do this.

First, you can use github’s β€œMerge pull request” button at the bottom of your pull request to merge your changes. This is only available when github can detect that there will be no merge conflicts with the base branch. If all goes well, you just have to add a commit message and click on β€œConfirm Merge” to merge the changes.

merge pull request button

Then confirm it

confirm Merge

And done :clap: :clap: :clap:

merged

You can now remove your branch from GitHub. You probably won’t gonna need it since all its changes got merged into master.

delete branch


Closing a Pull Request πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»/πŸ“–

You can always close PR.

πŸ‘‰ PR from this example: https://github.com/michalczukm/pull-request-tutorial-for-students/pull/2

Why?

:warning: If it is your teammate PR, you should probably contact with him/her and discuss that to avoid misunderstandings.

In general - be verbose, be good communicator, ask :blush:

How?

Close PR


More

⚠️ Danger zone, be careful - history rewrites down here ⚠️ I decided to create dedicated `danger zone` for this section and finally remove it, because I don't want to provide you **the simplest** (not uber-hight-crafter etc) way to work with Pull Requests. Re-writing git history is not part of it IMHO. Still - you can find this part in [original article](https://github.com/yangsu/pull-request-tutorial#squash-rebase-and-cherry-pick), since it was part of it.