Introduction to Collaborative Coding with GitHub

Elizabeth Waterfield

18/02/2026

Licence


Creative Commons Attribution 4.0

This work was originally created by Anna Krystalli from RSE-Sheffield under a MIT licence (original repository). It was subsequently adapted by Malika Ihle during her time at Reproducible Research Oxford, with the contributions of Adam Kenny. This work by Elizabeth Waterfield, Sarah von Grebmer zu Wolfsthurn, and Malika Ihle is licensed under a CC-BY-SA 4.0 Creative Commons Attribution 4.0 International SA License. It permits unrestricted re-use, distribution, and reproduction in any medium, provided the original work is properly cited. If you remix, transform, or build upon the material, you must distribute your contributions under the same license as the original.

Contribution statement

Creator: Waterfield, Elizabeth (orcid logo0009-0006-3725-6730)

Reviewer: von Grebmer zu Wolfsthurn, Sarah (orcid logo0000-0002-6413-3895)

Consultant: Ihle, Malika (orcid logo0000-0002-3242-5981)

Prerequisites

Prerequisites

Before completing this submodule, please carefully read about the necessary prerequisites.


Prerequisite Description Where to find it
R and RStudio installed Latest versions of both R and RStudio https://posit.co/download/rstudio-desktop/
Basic R skills 3.2. Introduction to R - Part I Module 3.2.
Advanced R skills 3.3. Introduction to R - Part II Module 3.3.
Basic Git skills 3.4. Introduction version control (Git) with RStudio Module 3.4.
GitHub account Create a personal account on GitHub github.com
Practice GitHub repo Fork the LMU OSC Collaborative-RStudio-GitHub repository to set up a practice repository for the exercises in this lesson See next slide

Instructors only: Practice repo

Before we collaborate, we need to set up a practise repository.

  • Log into your own GitHub account
  • Go to the LMU OSC’s Collaborative-RStudio-GitHub repository (see also https://github.com/lmu-osc/Collaborative-RStudio-GitHub/tree/main)
  • Create a fork by clicking on “Fork
  • Make sure you are set as the owner of the new repository and do not change the name of the forked repository then hit “Create fork

Now you have your practice repository!

You have copied all the materials from the LMU OSC Collaborative-RStudio-GitHub repository needed to do this session’s activities with your own GitHub account. This fork will be referred to as the main repository from here on and is the repository your learners will work on.

Questions from previous submodule



Any remaining questions about the most recent content and/or practical exercises?

Before we start: Survey time!

An image of a QR code that leads to a survey.

Starting Survey

Please complete survey labeled “OS-M3-S5-GitHub-starting_survey”.

What is your level of familiarity with working on GitHub?

  1. I have never heard of it before.

  2. I have heard of it but have never worked with it.

  3. I have basic understanding and experience with it.

  4. I am very familiar and have worked with it extensively.

Which of the following concepts or skills do you feel most confident about in relation to Git and GitHub? (Select all that apply)

  1. Creating and initializing a new Git repository.

  2. Making commits and writing meaningful commit messages.

  3. Cloning a repository from GitHub to my local machine.

  4. Pushing local changes to a remote repository.

  5. Pulling or fetching updates from a remote repository.

  6. Forking a repository and working on my own copy.

  7. I am not sure about any of these concepts.

On a scale of 1 to 5, how comfortable are you with using Git and GitHub for collaborative coding and version control? (1 = Not comfortable at all, 5 = Very comfortable)

  1. 1

  2. 2

  3. 3

  4. 4

  5. 5

Which statement best describes your experience with pushing and pulling in the context of working collaboratively on GitHub?

  1. I have never heard about either of these concepts.

  2. I have heard about these concepts before, but do not remember the exact details.

  3. I have a conceptual understanding of these concepts, but have not actively integrated them into my workflow.

  4. I have a conceptual understanding of both concepts and actively integrate them into my workflow.

Discussion of survey results


What do we see in the results?

Where are we at?

Previously:

  • Basic and advanced R skills (data manipulation, plotting, etc.)
  • Introduction to version control using Git

Up next:

  • Collaborating on projects remotely via GitHub
  • Tracking changes of each contributor on GitHub

GitHub and Open Science

GitHub offers a platform that enables transparent sharing, version control, and reproducible workflows. These are some of the core pillars of Open Science.

Learning goals

At the end of this session, you should be able to:

  • Navigate GitHub to collaborate on shared projects.
  • Fork and clone repositories to work locally without altering the main branch.
  • Commit, push, and pull changes to keep your project tracked and synchronized.
  • Design a collaborative workflow that enhances the openness and reproducibility of your own projects.

Covered in this session

  • GitHub workflow
  • Fork a repo
  • Clone a repo
  • Commit to a project
  • Push changes
  • Pull request
  • Merge changes
  • Pull upstream

Key terms and definitions

  • Git:
  • GitHub:
  • Git repository:
  • GitHub repository:
  • Branch:

Key terms and definitions

  • Git: A version control system that tracks changes made to files over time.
  • GitHub: A cloud-based, online platform that hosts Git-tracked projects.
  • Git repository: (also known as repo) A folder that contains your project files and the history of all changes made to them.
  • GitHub repository: An online or remote version of a Git repository that is hosted on GitHub’s servers.
  • Branch: A separate workspace where you can make changes without affecting the main project.

Collaboration challenges

Researchers can face many challenges when working collaboratively in a team with other researchers or in multi-organisational projects. Some of these are:

  • Poor communication
  • Disconnected collaboration
  • Limited transparency of project materials

Sound familiar?

Think about your past experience working collaboratively in a team. Did you face these challenges? Did similar or other challenges arise?

GitHub can help!

black and white image of GitHub's logo which resembles a cat with a tail on the left.

GitHub can help facilitate better collaboration between researchers. Here is how:

  • Better communication with messages describing changes made, inline commenting, and code reviewing.
  • The project materials are hosted and shared publicly or privately to support transparent collaboration.
  • By hosting the materials on online repositories, teams can work from anywhere, contribute asynchronously, and review each other’s work.

What is collaborative coding?

A drawing with lines connecting several persons to indicate collaboration.

With collaborative coding:

  • Multiple people can work and contribute on different parts of the same project at once.
  • Using Git and GitHub keep everyone’s work organized, merged, and tracked.
  • There’s more transparency and reproducibility in research projects.
  • The project/materials are reviewed and improved collaboratively.

Zooming out: GitHub collaborations

Note

Collaborative coding is only one way a team or a research group can work together on a single project. GitHub supports collaborative coding, but more generally collaboration on many different types of materials/projects, not just code.

Creating a workflow with GitHub

What a workflow using GitHub can look like:

A diagram showing a collaborative workflow using GitHub including actions like fork, clone, commit changes, push changes, and pull request.

Fork a repo

To fork a repo means to copy a collaborator’s repo to your own remote GitHub account.

  • Enables multiple contributors to work in parallel.
  • Make changes without affecting the original project.
  • Provides a personal workspace to test ideas.

Practical exercise 1: Fork a repo

Here’s a link to the main repository:

What is meant by “repo” here?

By repo on GitHub we mean one of two things:
1) the repository your instructor created on their own remote GitHub account for you to work on, or
2) an existing repo for practice e.g., https://github.com/lmu-osc/Collaborative-RStudio-GitHub/tree/main. Go to the repo that is available to you now.

Practical exercise 1: Fork a repo

An image highlighting the Fork button on the toolbar in a GitHub repository.

Something does not look the same?

Note that the screenshot may not match exactly because it depends which repo you forked from: You may be forking from your instructor’s GitHub instead of from the practice repo from ‘lmu-osc’.

Practical exercise 1: Fork a repo

An image showing the next steps after clicking 'Fork' including specifying the owner of the repository, the repository name, adding an optional description and a 'Create fork' button.

Fork a repo

You will see the fork of the repository on your GitHub account:

An image showing what the fork of the repository would look on the GitHub account including the name of the repository, where it was forked from, the status of the branch, and a 'Code' button.

Clone a repo

To clone a repo means to copy the project files onto your local device, such as your personal computer.

  • Connects your local work directly to the team’s online repository.
  • Makes it easy to sync updates between contributors.

Important difference: Forking vs. cloning

When you fork the repo, a copy is made on your remote GitHub account. When you clone a repo, a copy is downloaded from GitHub onto your local device.

Practical exercise 2: Clone a repo

An image of the forked repository highlighting the SSH Key that's given when you press 'Code' and then 'SSH'. This key is needed to clone the repository.

Practical exercise 2: Clone a repo

An image of an empty RStudio workspace where a user is selecting 'File' then 'New Project...' on the top toolbar to create a new project.

Practical exercise 2: Clone a repo

An image of the options given when creating a new project, highlighting that the 'Version Control' option should be selected for this project.

An image with the options 'Git' and 'Subversion' appearing, highlighting 'Git' as the option to proceed with.

Practical exercise 2: Clone a repo

An image of the settings for the Clone Git Repository highlighting the first text box since this is where the URL of the GitHub repository should go.

Placing this project in a new folder

First, make a new folder on your device. Then, you can change the path under “Create project as subdirectroy of:” to place this Git repository in that new folder. We are making a new folder because it is advisable that each folder has its own Git database.

Clone a repo

An image of the 'Files' tab in RStudio displaying the files of the cloned GitHub repository.

Now, when you click on the “Files” tab in RStudio, you should see all the files from the main repository.

Commit to a project

To commit to a project means to save the file with the changes you made locally in your version control system.

  • Records progress in small and trackable steps
  • Lets others see exactly what was changed
  • Makes it possible to revert or review changes if there are bugs

Avoiding merge conflicts

Merge conflicts happen when Git cannot automatically combine changes because the same part of a file was edited differently by two collaborators. Frequent commits help with resolving conflicts because they create clear checkpoints in your project’s history. GitHub also offers GitHub issues as a communication tool to resolve conflicts.

Practical exercise 3: Commit

Before you commit to a project, you need to make some changes to the project.

An image of the 'Files' tab in RStudio highlighting the 'Copy' button under the 'More' options on the toolbar within the tab.

Practical exercise 3: Commit

Screenshot with an example of a name for a copied file of a project in the RStudio GitHub integration.

Practical exercise 3: Commit

Screenshot of an R script defining parameters for sig2, species.name, and color with the value #311DB3.

Practical exercise 3: Commit

An image of the 'Git' tab in RStudio where the copied file is selected.

Practical exercise 3: Commit

An image showing the selected file on the left and a text box on the right for a Commit message describing the changes made to the file.

You made a contribution!

Great, now you have made changes! You added a file with your parameters on a shared project and committed it. Let’s take a minute (literally) and recap what you did to achieve that.


Activity: one-minute paper!

  • You have 60 seconds to write down what steps you took to collaborate on this project so far.
  • Think of the names of the actions, in which order you did them, and how can this be beneficial to you as a collaborator.

Push changes

To push changes means to upload your local commits from your local computer to the remote repository on GitHub.

  • Keeps the online version of the project up to date.
  • Makes your work visible to all contributors in real time.
  • Enables others to pull your latest edits and build on them.

Practical exercise 4: Push

A screenshot of the 'Git' tab in RStudio highlighting the button 'Push' on the toolbar to push the changes to GitHub.

Push changes

If you successfully pushed your changes, you would see a pop up box like the one below:

An screenshot showing the message one would receive if the push action was successfully completed.

Push changes



Important step: refresh the page

Refresh the page of your forked repository on GitHub and you should see your new file with the commit message next to it. Refreshing the page is an important step to update your forked repository with the new file you added.

Pre-break quiz

An image of a QR code that leads to a survey.

Pre-break quiz

Please complete survey labeled “OS-M3-S5-GitHub-prebreak_quiz”.

What is GitHub mainly used for by a team working on the same project?

  1. Editing photos online

  2. Hosting and collaborating on code or research projects

  3. Sending emails and important messages to team members

  4. Backing up personal files only

On GitHub, why would you fork a repository?

  1. To delete the original repository and start a new one

  2. To download a copy of the remote repository to your local computer

  3. To create your own remote copy of someone else’s repository on GitHub

  4. To merge your work into the main branch and have everyone’s work in one folder

What does it mean to clone a repository?

  1. You download the repository from GitHub to your local device

  2. You create a backup of your GitHub account

  3. You make your repository private

  4. You copy code into a new file then upload it to GitHub

When you make changes to a file then commit it, what happens?

  1. It deletes all previous versions of your file

  2. It sends your work directly to the main repository

  3. It saves your changes locally (on your device)

  4. It approves changes made by other collaborators

After I made changes and committed it, why would I then push the changes?

  1. To create a new repository

  2. To incorporate my changes into the files of the main repository

  3. To notify my teammates that I made changes

  4. To upload the work I saved locally to GitHub

Break! 15 minutes

Post-break quiz discussion


What do we see in the results?

Pull request

To make a pull request means asking the repository’s owner to review the changes you made (from your fork or branch) and merge them into the main repository on GitHub.

  • Creates a space for discussion and code review before incorporating changes.
  • Encourages feedback and peer learning.
  • Maintains project quality and consistency.

Practical exercise 5: Pull request

A screenshot of the forked GitHub repository highlighting the button 'Open pull request' that appears when you click the 'Contribute' button.

Practical exercise 5: Pull request

A screenshot of the GitHub page showing the ‘Open a pull request’ interface where the base and head repositories are highlighted in green boxes, and the title field says ‘Please add text here.’

Practical exercise 5: Pull request

A screenshot of an open GitHub pull request titled ‘add malika rocks parameters,’ with the ‘Pull requests’ tab highlighted in green.
  • You should see a conversation tab around your pull request in the original repository.

Merge changes

To merge changes means to combine updates from different branches or contributors into one unified version of the project.

  • Brings everyone’s contributions together.
  • Ensures new work integrates smoothly with the main branch.
  • Helps resolve overlapping edits or conflicts between files.

How to merge changes

An image of a GitHub pull request showing the ‘Files changed’ tab highlighted and code edits in green.

The owner of the main repository:

  • Goes to their “Pull requests” tab to inspect the changed files
  • Ensures that the parameters were inputted correctly so as to not break down their code down the line

What’s happening here?

In this example, the file “malika_rocks.R” is being reviewed to then be added to the “params” sub-folder in the main repository project files.

How to merge changes

A screenshot of a GitHub pull request ready to merge, showing a comment box with the text ‘It looks great! thanks for your data.’

If everything looks fine, the owner will:

  • Go back to the “Pull request” tab
  • Write a comment
  • Merge the pull request and confirm the merge

How to merge changes

Now let’s see all the contributions work together!

A screenshot of the 'Git' tab in RStudio with the 'Pull' button highlighted in a red box.

  • The owner of the main repository will pull the new contributed files from GitHub into their local repository using the “Pull” button in RStudio.

What should I see?

All the contributions that were merged into this repository should show up in the ‘Params’ sub-folder in the local repository.

How to merge changes

A screenshot of an R Markdown file in RStudio showing the Knit button highlighted in a red box and example code for an HTML document.
  • Then, the owner will locate and open the “plot-trait-evolution.Rmd” file in the repository which sources all the contributed files.
  • Once opened, they will click the “Knit” button on the toolbar to generate plots and figures based on the parameters that were contributed.

What does Knit do?

Knitting a Rmarkdown file means rendering the Rmarkdown code. This integrates the R code and Markdown code into a defined format (for example: an html file).

How to merge changes

An image of a line graph showing trait evolution over time for two species, anas_krystallinus and malika_rocks depicted by an orange and blue line respectively.

An image of skull images for two species 'No. 35 anas_krystallinus' and 'No. 18 malika_rocks' with a heading inviting users to find the skull associated with their species.

  • An html document will appear that shows the contributions plotted altogether on a line graph and images of skulls under the names of the species.

You did it! You collaborated on GitHub!

Merge changes - live demo!



Now let’s see what that looks like for this project with a live demonstration using your contributions!

Pull upstream

To pull upstream means to update your local or forked repository with the latest changes from the original (upstream) repository.

  • Keeps your local copy aligned with the main project’s progress.
  • Prevents outdated or conflicting edits when working in teams.
  • Encourages synchronization across all contributors.

Practical exercise 6: Pull

git checkout main


git checkout

This command sets the branch to the one you want to pull the modifications from. In this case, you want to pull the changes from the main branch of the remote main repository into your the main branch of your local repository.

Practical exercise 6: Pull

git pull git@github.com:ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git


How to properly format this command?

Replace the “ORIGINAL_OWNER” with the name of the GitHub account that owns the main repository. Replace “ORIGINAL_REPOSITORY” with the name of the main repository that has the original project files.

Practical exercise 6: Pull

This is an example.

This is an example.

Practical exercise 6: Pull

git push
A screenshot of an RStudio terminal showing the command ‘git push’ with a successful push to the GitHub repository.

This is an example.

And that is it!

You just completed the entire workflow!

  • You started with making a fork of the main repository with the project files to make your changes without affecting anyone else’s work.
  • Then you pushed and had these changes merged into the main repository.
  • Lastly, you pulled these changes so that your copies (remote and local) can stay updated with the changes made.

Recap

What actions did we learn in today’s lesson?

  • Fork a repo: make your own copy on GitHub
  • Clone the repo: bring it to your local computer
  • Commit: make changes locally
  • Push: upload those changes to your fork on GitHub
  • Pull request: propose those changes to the main/original repo
  • Merge: the project owner merges your pull request into the main branch
  • Pull upstream: after the merge, you pull the updated main branch from the original repo to sync your local copy

Recap activity

Remember this illustration?

Fill in the missing words with the actions we learned today!

Recap activity

Check your answers!


Download the completed diagram

Collaborative coding with GitHub

Now that you have all gained some experience working collaboratively using GitHub, let us reflect with some questions:

1. How can collaborative coding with GitHub be useful?


2. What potential problems could still arise using this workflow?

Take-home message



Consider the following question:

If you had to explain to a new teammate why using GitHub for collaboration is valuable, what key ideas from today would you talk about?

Git from the terminal

  • Several actions in collaborative coding on GitHub can also be performed directly using Git commands in a so-called terminal instead of using the functions in RStudio.

What is a terminal?

It is a text-based tool where you can type commands to run programs such as Git. If you downloaded Git for Windows, you can right-click in a folder > Show more Options > Git Bash here to open Git Bash. On MacOS, you can use the built-in Terminal by going to Finder > Applications > Utilities > Terminal.

Assignment

Here is an activity sheet to learn and practice Git commands in the terminal:


Download the GitHub activity sheet

To conclude: Survey time!

An image of a QR code that leads to a survey.

Final survey

Please complete survey labeled “OS-M3-S5-GitHub-finishing_survey”.

Which of the following concepts or skills do you feel MOST confident about in relation to Git and GitHub? (Select all that apply)

  1. Forking a repository and working on my own copy.

  2. Cloning a repository from GitHub to my local machine.

  3. Making commits and writing meaningful commit messages.

  4. Pushing local changes to a remote repository.

  5. Pulling or fetching updates from a remote repository.

  6. I am still not sure about any of these concepts.

On a scale of 1 to 5, how comfortable are you right now with using Git and GitHub for collaborative coding and version control? (1 = Not comfortable at all, 5 = Very comfortable)

  1. 1

  2. 2

  3. 3

  4. 4

  5. 5

When you worked collaboratively on this GitHub project, what aspect did you find most challenging?

  1. Understanding Git commands (commit, push, pull)

  2. Remembering all the steps

  3. Navigating the GitHub interface

  4. Other

Discussion of survey results


What do we see in the results and how do they compare to the previous ratings?

References

Thanks!

See you next class :)

Pedagogical add-on tools for instructors

Attribution and license details UNFINISHED

  • This slide should contain information about the license and attribution details of this current set of slides.

  • The default for the created materials is CC-BY-SA 4.0

    • = Creative Commons license that allows others to share, adapt, and build upon the original work
    • only if they attribute the creator and also share their new work under the same terms
    • allows for both commercial and non-commercial use of the licensed material
  • Components of attributions:

    • Title
    • Author
    • Source
    • License