Collaborating
Overview
Teaching: 25 min
Exercises: 0 minQuestions
How can I use version control to collaborate with other people?
Objectives
Clone a remote repository.
Collaborate pushing to a common repository.
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 will 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. On GitHub, click the settings button on the right, then select Collaborators, and enter your partner’s username.
To accept access to the Owner’s repo, the Collaborator needs to go to https://github.com/notifications. 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”. Start by clicking the “Clone or download” button on the repository’s GitHub page.
This will give you the repository’s URL and might give you a “Download in
Desktop” link. If you have that link, go ahead and click it. If you don’t have
button, copy the repository’s URL to your clipboard and then, in GitHub Desktop,
choose File >> Clone a repository
. Choose the repository’s containing folder
in “Local Path” and click “Clone.”
No Changes
When you click on that repository in GitHub Desktop, it appears like there’s nothing there. Why is that? What do you have to do to see the files?
Solution
There is nothing there because GitHub Desktop only shows you the changes made to files since the last commit. It does not list all the files in the directory. To see the repository, you need to navigate to it in your file browser, and to edit the files you need to open them in a text editor.
Push and pull a change
The Collaborator should open one of the files in the repository and add a line. Then they can commit the changes (with an informative message!) and click “Push changes”. How does the owner get those changes reflected in their own copy of the repository?
Solution
Once the changes have been pushed to GitHub’s servers, the owner goes to
Repository >> Pull
to update the repository on their machine.
Now the three repositories (Owner’s local, Collaborator’s local, and Owner’s on GitHub) are back in sync.
A Basic Collaborative Workflow
In practice, it is good to be sure that you have an updated version of the repository you are collaborating on, so you should always pull before making our changes. The basic collaborative workflow would be:
- update your local repo with
Repository >> Pull
- make your changes and make sure they’re properly staged,
- commit your changes with an informative commit message, and
- upload the changes to GitHub with
Repository >> Push
or the “Push changes” button.It is better to make many commits with smaller changes rather than one commit with many changes: small commits are easier to read and review.
Switch Roles and Repeat
Switch roles and repeat the whole process.
Comment Changes in GitHub
The Collaborator has some questions about a change made by the Owner on one particular line and has some suggestions to propose.
With GitHub, it is possible to add comments on the diff of a commit. Over the line of code to comment, a blue comment icon appears that will open a comment window if you click on it.
The Collaborator posts their comments and suggestions using the GitHub interface.
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?
Key Points
Publishing a repository to GitHub lets multiple people work on it at once and keeps a master copy
Frequent pushing and pulling keeps the copies in sync.