For the next step, get into pairs. One person will be the “Owner” and the other will be the “Collaborator”. The goal is that the Collaborator add changes into the Owner’s repository. We will switch roles at the end, so both persons will play Owner and Collaborator.
The Owner needs to give the Collaborator access. In your repository page on GitHub, click the “Settings” button on the right, select “Collaborators”, click “Add people”, and then enter your partner’s username.
To accept access to the Owner’s repo, the Collaborator needs to go to https://github.com/notifications or check for email notification. Once there she can accept access to the Owner’s repo.
Next, the Collaborator needs to download a copy of the Owner’s repository to her machine. This is called “cloning a repo”.
The Collaborator doesn’t want to overwrite her own version of weather.git
, so needs to clone the Owner’s repository to a different location than her own repository with the same name.
To clone the Owner’s repo into her Desktop
folder, the Collaborator enters:
$ git clone git@github.com:mo-eormerod/weather.git ~/Desktop/mo-eormerod-weather
Replace ‘mo-eormerod’ with the Owner’s username.
If you choose to clone without the clone path (~/Desktop/mo-eormerod-weather
) specified at the end, you will clone inside your own weather folder! Make sure to navigate to the Desktop
folder first.
The Collaborator can now make a change in her clone of the Owner’s repository, exactly the same way as we’ve been doing before:
$ cd ~/Desktop/mo-eormerod-weather
$ nano shipping-forecast.md
$ cat shipping-forecast.md
New high expected Dover 1028 by 0600 tomorrow.
Low Trafalgar 1013 losing its identity
$ git add shipping-forecast.md
$ git commit -m "Add in the shipping forecast"
1 file changed, 2 insertion(+)
create mode shipping-forecast.md
Then push the change to the Owner’s repository on GitHub:
$ git push origin main
Enumerating objects: 4, done.
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/mo-eormerod/weather.git
9272da5..29aba7c main -> main
Note that we didn’t have to create a remote called origin
: Git uses this name by default when we clone a repository. (This is why origin
was a sensible choice earlier when we were setting up remotes by hand.)
Take a look at the Owner’s repository on GitHub again, and you should be able to see the new commit made by the Collaborator. You may need to refresh your browser to see the new commit.
To download the Collaborator’s changes from GitHub, the Owner now enters:
$ git pull origin main
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 3 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From https://github.com/mo-eormerod/weather
* branch main -> FETCH_HEAD
9272da5..29aba7c main -> origin/main
Updating 9272da5..29aba7c
Fast-forward
shipping-forecast.md | 2 +
1 file changed, 2 insertion(+)
create mode 100644 shipping-forecast.md
Now the three repositories (Owner’s local, Collaborator’s local, and Owner’s on GitHub) are back in sync.
Switch Roles and Repeat
Switch roles and repeat the whole process.
Review Changes
The Owner pushed 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?
Solution (Solution). On the command line, the Collaborator can use git fetch origin main
to get the remote changes into the local repository, but without merging them. Then by running git diff main origin/main
the Collaborator will see the changes output in the terminal.
On GitHub, the Collaborator can go to the repository and click on “commits” to view the most recent commits pushed to the repository.
Version History, Backup, and Version Control
Some backup software can keep a history of the versions of your files. They also allows you to recover specific versions. How is this functionality different from version control? What are some of the benefits of using version control, Git and GitHub?
Keypoints
git clone
copies a remote repository to create a local repository with a remote calledorigin
automatically set up.
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 on 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 her comments and suggestions using the GitHub interface.