A Visual Guide to Pull Requests for my students. The simple way π
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.
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.
There are 2 main work flows when dealing with pull requests:
Here we are going to focus on 1.
π PR from this example: https://github.com/michalczukm/pull-request-tutorial-for-students/pull/1
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
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.
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.
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.
Or with constraints, like Review reqired
(thats how we do it :blush:)
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:
: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
So, you received a PR. What next :question:
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.
Then confirm it
And done :clap: :clap: :clap:
You can now remove your branch from GitHub. You probably wonβt gonna need it since all its changes got merged into master
.
You can always close PR.
π PR from this example: https://github.com/michalczukm/pull-request-tutorial-for-students/pull/2
: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: