Adding collaborators

Exercise 1

Find one or two collaborators. Go to GitHub (or GitLab) and add each other as collaborators to your repositories.

GitHub: Settings > Manage access > Add people

GitLab: Project information > Members > Invite members

Publish changes without review

Exercise 2

Now, it’s time to start collaborating.

  1. Clone your collaborators repository into a new directory (not inside your repository!)
  2. Make some constructive changes
  3. Stage, commit, and push all changes to your collaborators remote repository
  4. Pull and review the changes your collaborator has made to your repository
  5. Comment on one of the changes to your repository on GitHub
You may review the changes to your repository on GitHub or in RStudio. In RStudio, click the little clock icon in the Git pane to open the commit history and review the changes.
git clone
git add .
git commit -m "Constructive changes"
git push

Open a pull request

Exercise 3

Open your browser and navigate to your collaborator’s GitHub repository.

  1. Choose a file and edit it in your browser
  2. Open a pull request
  3. Review the changes your collaborator has proposed to your repository, accept them, and merge the pull request

After creating a new branch with git branch my-branch you have to switch over to that branch before making any edits with git checkout my-branch.

When pushing a newly created branch for the first time, you need to specify where the branch should be pushed to (git push origin my-branch).
git pull
git branch revision
git checkout revision
git add .
git commit -m "My changes"
git push origin revision

Exercise 4

Start a conversation. Open your collaborator’s repository in RStudio.

  1. Pull the latest changes from the remote repository
  2. Create a new branch
  3. Edit multiple files, stage, commit, and push the changes
  4. Open your collaborator’s GitHub repository, find your branch, and open a pull request
  5. Review the changes your collaborator has proposed to your repository and request a change
  6. Make the requested changes to your PR
  7. After reviewing the updated pull requests to your repository, accept and merge it
You can revise your pull request simply by editing the branch in RStudio and pushing the committed changes to GitHub as usual. The pull request will be updated automatically.

Merge conflicts

Bonus

Together with your collaborator, create a merge conflicts on each others repositories.

  1. Pull the latest changes from the remote repository
  2. Choose a file and edit the same line in that file in your RStudio and commit the change (do not push, yet).
  3. Let your collaborator push the change to your repository and then try pushing yourself.
  4. Pull the latest changes from the remote repository
  5. Resolve the merge conflict
  6. Push your changes to your repository
When resolving a merge conflict, you can do so in any way you see fit. You can keep your changes or those of your collaborator. You may also combine the changes or discard both and come up with something new.

The file containing the merge conflict might look something like the following.

<<<<<<<< HEAD
Your changes
========
Your collaborator's changes
>>>>>>>> b8e009f666b984509b28a8dedc18e45811be94a6

After resolving the conflict, the file could look as follows.

Your and your collaborator's changes
Then you can just stage and commit the conflict resolution as usual.