Github allows you to give permissions to users to contribute to a repository (read, write, or admin access). But the best type of workflow is one where users don't push directly to the git repo. Instead it is based around pulls.
How do we contribute to a project that we don't own?
Here's a github organization for our class: https://github.com/sbu-python-class
and here's a simple repo in this organization: https://github.com/sbu-python-class/test_repo
An organization is meant to be used by a collection of developers who
can all have different access permissions. It provides tools for
managing who can do different things to the repos under its control.
Let's clone this repo:
git clone git@github.com:sbu-python-class/test_repo.git
cd test_repoNow, let's each try to add a file of the form username.txt containing your full name. Ex:
echo Michael Zingale > zingale.txt
git add zingale.txt
git commitNow try to push it to the repo we clone:
git pushwhat happened?
The issue is that you don't have write permission to that repo, since I own it. So you are denied access.
This is okay. The workflow that github emphasizes is one based around pulls not pushes, so let's see how we do that.
First, we need to fork the repo -- this creates a clone under our control that we can do with as we please. Click on the "fork" button.
:align: center
:alt: The github webpage for our test repo with the "fork" button circled
It may ask you where you want the fork to live—you want it to live under your profile / username.
This will bring you to a new github page, displaying the fork, with a
URL that should look something like: https://github.com/zingale/test_repo
Now click on the code button and copy the SSH location.
:align: center
:alt: our fork of the class test repo github web page with the code button pressed
We want to add this fork as a new remote:
git remote add myfork git@github.com:zingale/test_repo.git(again, make sure you replace that with the link to your repo).
Now you can do:
git push myforkIf you reload your github page, you should see your change there.
Now we can do all pull-request. Select "pull requests"
:align: center
:alt: The github webpage of our fork of the class test repo
Then click on the "New pull request" button, and you'll see something like:
:align: center
:alt: The github weboge showing a pull request, highlighting the difference between the fork and the upstream repo.
This is showing that you are asking to merge the changes in your fork into the
class test_repo repository.
Click on create pull request, type in a comment about what this does, and then click on the create pull request button again.
Now it is out of your hands.
The owner of the class repo (me) will get a notification that you want to incorporate your changes into the class repo, and I can merge them via the github web tools.
The overall workflow that we did: fork, push to our fork, issue a PR, looks like:
:align: center
:width: 80%
:alt: a diagram showing our workflow between the github class repo, our local macine, and our fork.
Let's take a tour of our class notes on github: https://github.com/sbu-python-class/python-science
There are a lot of other features that github provides that we can use to make our life easier, including:
-
github actions : automating some workflows (like testing) on our code
-
github pages : building and hosting web pages for our project