Version Control with Git

Collaborating

Learning Objectives

  • Clone a remote repository.
  • Collaborate pushing to a common repository.

For the next step, get into pairs. One person will be the “Owner” (this is the person whose Github repository will be used to start the exercise) and the other person will be the “Collaborator” (this is the person who will be cloning the Owner’s repository and making changes to it).

The Owner needs to give the Collaborator 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 Collaborator needs to work on this project locally. He or she should cd to another directory (so ls doesn’t show a planets folder), and then make a copy of the Owner’s repository:

$ git clone https://github.com/vlad/planets.git

Replace ‘vlad’ with the Owner’s username.

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

After Creating Clone of Repository

After Creating Clone of Repository

The Collaborator can now make a change in his or her copy of the repository:

$ cd planets
$ 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/vlad/planets.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/vlad/planets
 * branch            master     -> FETCH_HEAD
Updating 9272da5..29aba7c
Fast-forward
 pluto.txt | 1 +
 1 file changed, 1 insertion(+)
 create mode 100644 pluto.txt

Review changes

The Owner push commits to the repository without giving any information to the Collaborator. How can the Collaborator find out what has changed with command line? And on GitHub?

Comment changes in GitHub

The Collaborator has some questions about one line change made by the Owner and has some suggestions to propose.

With GitHub, it is possible to comment the diff of a commit. Over the line of code to comment, a blue comment icon appears to open a comment window.

The Collaborator posts its comments and suggestions using GitHub interface.