Making and merging Pull Requests on GitHub#
Contents of this notebook:
How to make a pull request on GitHub
Resolving merge conflicts
Reviewing and merging pull requests
1. How to make a pull request (PR) on GitHub#
To set the scene, let’s imagine that you have made changes on the local copy of your repository and you want to add those changes to the GitHub repo, so your collaborators can see them. For simplicity, let’s say the name of your branch on your local computer is testing_branch
. To push your changes to the remote (of course, don’t forget to commit your changes before this!), you will need to run the following command on your terminal:
git push origin testing_branch
In this command, we basically tell git to push our local changes to the remote called origin
(which is just the GitHub repo), to the branch called testing_branch
. Note that we can call the remote branch whatever we want, it does not have to be the same as the local branch name.
After this, if we go to our GitHub repo page, on the top of the screen, there is a message, stating that there were changes made to the testing_branch
. On the right side of this message there is a button that says Compare & pull request
. If you press that button, you should see a new window that lets you name your pull request (PR) and add a description of the changes you have made.
2. Resolving Merge Conflicts#
It is very common for projects where multiple people are working on files at the same time to have merge conflicts. Imagine a scenario where you and your friend John have changed things on the same file in a way that is not easy to combine into one file. This generally causes a merge conflict. There are multiple ways to resolve this. One of them is resolving merge conflicts in your Pull Request (PR)! If your Pull Request has merge conflicts, near the bottom of it you can see a button called Resolve conflicts
. If you press that, it will open a text editor on GitHub with the part where the merge conflict occurs. You can by hand remove the part that causes a conflic by leaving the version of the text/code that you want to be on the main combined code.
After doing this, on the top of the text editor press Mark as Resolved
. And just like that, you have resolved a merge conflict!
3. Reviewing and Merging Pull Requests#
After resolving all the merge conflicts, we are ready to merge your pull request into the main branch. Well, almost. One last thing is left for your colleagues to review your Pull Request. They can do this by going into the Files Changed
submenu of your PR and leaving comments or approving your PR. It is generally a good coding practice to get at least one approved review on your PR before merging it. This ernsures that there are no minor mistakes or typos in your changes!
After getting review, you can finally merge your PR. Scroll down to the end of the page of your PR and click on Merge pull request
.
Additional guides#
You can also check out the GitHub documentation on Pull Requests here.