Version Control with Git

Collaborating

Learning Objectives

  • Collaborate pushing to a common repository.

For the next step, get into pairs. Pick one of your repositories on GitHub to use for collaboration. If you were here yesterday, choose the use the software-carpentry-2016 that you made yesterday

The partner whose repository is being used needs to give the other person access. On GitHub, click the settings button on the right, then select Collaborators, and enter your partner’s username.

Adding collaborators on GitHub

Adding collaborators on GitHub

The other partner should cd to another directory (so ls doesn’t show a software-carpentry-2016 folder), and then make a copy of this repository on your own computer:

$ git clone https://github.com/mqwilber/software-carpentry-2016.git

Replace ‘mqwilber’ with your partner’s username (the one who owns the repository).

git clone creates a fresh local copy of a remote repository.

After Creating Clone of Repository

After Creating Clone of Repository

The new collaborator can now make a change in their copy of the repository:

$ cd software-carpentry-2016
$ nano pluto.txt
$ cat pluto.txt
It is so a planet!
$ git add pluto.txt
$ git commit -m "Some notes about Pluto"
 1 file changed, 1 insertion(+)
 create mode 100644 pluto.txt

then push the change to GitHub:

$ git push origin master
Counting objects: 4, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 306 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://github.com/mqwilber/software-carpentry-2016.git
   9272da5..29aba7c  master -> master

Note that we didn’t have to create a remote called origin: Git does this automatically, using that name, when we clone a repository. (This is why origin was a sensible choice earlier when we were setting up remotes by hand.)

We can now download changes into the original repository on our machine:

$ git pull origin master
remote: Counting objects: 4, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 3 (delta 0)
Unpacking objects: 100% (3/3), done.
From https://github.com/mqwilber/software-carpentry-2016
 * branch            master     -> FETCH_HEAD
Updating 9272da5..29aba7c
Fast-forward
 pluto.txt | 1 +
 1 file changed, 1 insertion(+)
 create mode 100644 pluto.txt

Raise an issue on Github and fix it

Have one member of your group raise an Issue (look at the issues tab) in the github software-carpentry-2016 repository on which you all are collaborating. It can be something like

@mqwilber needs to add a bibliography file

Then have the partner to which the task is assigned make the appropriate changes in their local repo, push it to github, and close the issue. The person who made the issue should then pull the repo and confirm the changes are present on his/her local branch