GitHub pull requests¶
In Module 1, you learned a little bit about GitHub and how it can be used to share code between developers and with the general public. More specifically, you used the command-line interface (CLI) to clone repositories (repos) to your local computing environment. In this lesson, weâll continue the discussion and explore two more features of GitHub: the web user interface (UI) and pull requests (PRs).
Web UI¶
Chances are, you have already seen the GitHub web UI if youâve cloned a repo before, because thatâs where you will find the correct URL to clone. As an example, here is the repo for this textbook.
As you can see, the UI is fairly clean with many symbols, lots of whitespace, and light colors. This simplicity was intentionally designed to better surface repo elements and key GitHub features. Moreover, the developers of GitHub realized that in order to elevate GitHub to the next level and increase platform adoption, they had to start enabling more CLI features to be accessible through the UI. This not only improves the user experience for everyone (who doesnât like point-and-click, drag-and-drop?), but also enables less programming-savvy users to collaborate on projects.
On the main page of this textbookâs repo, you will notice that one of the most prominent features on the right-hand side is the Contributors list. This panel lists everyone who has made at least one change to at least one file in this repo. It is sensible for this to be featured since that is one of the purposes of using GitHub and credit should be given where credit is due. However, youâll also notice that itâs a little sad at the momentâEnze is the only contributor. đą
But fear not! As stated on the first day, we are a team, and a team functions best when everyone contributes, so you will all soon become contributors on this wonderful team project of ours. đ
Presentation abstract¶
Pull requests¶
In GitHub lingo, the phrase associated with a personal contribution to a project is a pull request, or PR. When you âopen a PRâ or âsubmit a PR,â what this means is that you made some changes to your personal version of a repo and youâre ready to incorporate those changes into the main, public version of that repo. The âpullâ part of the name refers to the fact that the main project has to grab your changes, and the ârequestâ part of the name refers to the fact that the maintainers of the project need to review and accept your changes before they can be incorporated (merged in GitHub lingo).
PRs are used all the time on GitHub and in software engineering as it allows for individual contributions while maintaining certain consistency checks. While we cannot git into all the details at the moment đ€Šâ, we hope you can at least appreciate why weâre teaching you this concept and now we will put these ideas into practice. Once you have made some changes, submitted a PR, and that PR gets approved, you will become a contributor on this project!
Final presentation page¶
In a different tab, navigate to this page of the textbook: Final presentations. On that page, hover over Octocat and click â suggest edit.
Fork the repo¶
This will take you to a page in the web UI that looks like the following:
Since you are not a maintainer for the repo (only Enze is), you have to make a copy of the files and can only edit those copies. Making your personal copy of a repo is called a fork đŽ in GitHub lingo, and you should click Fork this repository. This should then take you to an interface that looks like the following:
Add your information¶
Now find your section on that page and add the information related to your presentation. If you donât have the information ready, no worries. Cancel the changes for now (Enze will be periodically merging in othersâ changes) and you can always come back to it later by following the same steps.
Attention
To avoid this going, ha-ha, terribly wrong (i.e., âmerge conflictsâ in GitHub lingo), please make sure you edit your section and your section only. Please donât touch any other lines, including adding/removing spaces in othersâ sections!
For the emoji, title, and description, replace the entire [your_XXX]
parts.
Emojipedia is a good source for selecting cross-platform emojis.
For the image, change just temp.png
to the name of your own figure file, with the extension.
Your figure name has to be unique to you, so we suggest something like name_final.png
(e.g., enze_final.png
), provided this is what you named the actual figure (PNG) file on your computer!
Weâll upload this image to the repo shortly.
Propose changes¶
When you have completed your section, scroll to the bottom and create a short title for this set of edits that you made (see above). When you are done, click Propose changes to take you to the next page where you can see the lines youâve changed. Near the top, you should see a box that says something like compare: patch-1. Make a note of the number.
Uploading your figure¶
Halfway there! Youâve updated your presentation details, which now references the figure you made, but that figure isnât in the repo yet! Time to change that.
First, navigate to your forked repo by clicking [Your avatar in the top-right corner] >
Your repositories >
mi-book, which should take you to a very similar page as the main repo, except the header has the image in the sidebar, saying âforked from enze-chen/mi-book.â
Next, find the dropdown that says master ⟠and select the name associated with the change you made earlier, which should be patch-1
or something similar.
As the surrounding text implies, these are different branches of your project, and this is an important feature when using git.
In essence, brances allow you to keep several different versions of your code (with say, different files edited/present in each one) so that different project members can independently work on different sections/features, and only merge them with the main branch (called master
) when ready.
When you proposed changes with your presentation information, those changes were saved into the patch-1
branch, and so you want to add your figure to that branch as well.
Click the branch name to switch you to that branch.
Next, navigate by clicking on the folders to assets/fig/week_3/14
where you should only see temp.svg
, temp.png
, and maybe a few other figures, depending on how quickly Enze has merged other studentsâ PRs.
Once here, click on Add file >
Upload files and choose the image from your computer (make sure it matches the name you entered in final_presentations.md
).
Then enter a descriptive title for this change and click Commit changes (commit directly to the patch-1
branch).
Finally, the PR!¶
Â
Almost there! Now you should see a yellow banner at the top with a fat Compare & pull request button. Click it!!
Â
This takes you to the PR dialogue, and you should note the following:
Make sure that at the top, you are merging the correct source branch on the right-hand side (
your_username/mi-book:patch-1
or equivalent, notmaster
) to the correct destination branch on the left-hand side (enze-chen/mi-book:master
, notgh-pages
).Write a descriptive title for your PR.
Leave the box âAllow edits by maintainersâ checked â.
At the bottom, you can further verify that the â2 files changedâ are
final_presentations.md
andname_final.png
.
If everything looks good, you can click Create pull request and then ping Enze on Slack! Woohoo! đ
Submission deadline
A reminder that you should submit your PR by 11:59PM PT Wednesday, 07/14. This gives us enough time to merge it in and fix things if something breaks.
Wait, I made a mistake!¶
Thatâs alright, just make the changes to your copy of the files/figures in your patch-1
branch and submit another PR to enze-chen/mi-book:master
.
Thatâs the beauty of it. đ