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.

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 planets folder), and then make a copy of this repository on your own computer:

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

Replace ‘vlad’ 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 planets
$ emacs 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