Overview
Teaching: 15 min
Exercises: 15 minQuestions
How do I contribute to repositories I have not been given permission to modify?
Objectives
Fork a public repository
Create a pull request to the original repository
There are no shortage of projects on GitHub, and you will not be able to modify those repositories unless the owner gives you permission. Usually, owners do not like to give permission to strangers, so instead rely on selectively pulling commits from a forked version of their primary repository.
To create a fork if your partner’s repository, go to their GitHub page, select the repository, and click on the ‘fork’ button:
Now clone the repository normally
$ git clone https://your-fork-of-your-partners-repo
Make changes to the files in this repository the same way you would in any other. This is now your copy of the code, to do whatever you like with (within the bounds of the license agreement, as will be discussed later).
Add another conversion tool to the growing list of functions in conversions.py
# My Conversion Tools
def dollars2cents(dollars):
cents = dollars * 100
return cents
...
def mole2atoms(mol):
atoms = mole * 6.02e23
return atoms
Create a commit, and push it to GitHub.
$ git add conversion.py
$ git commit -m "Add mole to atoms converter function"
$ git push
You could now email the maintainer of the original repository to tell them about the cool new function you’ve written, and they could use the unique hash identifier of your commit to pull those changes into their own code base, but GitHub makes the process much easier with Pull Requests.
Compare the changes you want to add to your pull request and send it off
The maintainer will most likely get an email about the new pull request, but if they don’t, it will be visible to them next time the log into GitHub:
Accepting the request is as simple as hitting the green button, BUT BE
CAREFUL!. Always look at the cimmit history, and check what changes
are included in the pull request. You don’t want the merge to break
your code. Check the ‘Commits
’ and ‘Files changed
’ tabs to be sure.
Practice makes perfect
Fork your partner’s repository and submit a pull request.
Also accept the pull request your partner has submitted.
Be wary of the big green button
Try to think of some reasons you may want to reject a pull request.
Fork a public repo
Browse the GitHub Showcase and try to find a repository that you think you might find useful (or that you may want to contribute to!). Fork it!
Key Points
Any public repository on GitHub can be forked and modified.
If you make changes to a forked repository, you can request that the maintainer of the original repository merges your changes into theirs.