22 Collaborating on GitHub

Why use GitHub for collaboration?

  • version control
  • integration with RStudio
  • industry standard
  • share your work with others (“repositories” are public by default)



How to use GitHub?

Happy Git and GitHub for the useR provides an extensive introduction to the bells and whistles of GitHub. We’ll focus on the basics:

  • If you are new to GitHub:
    • Sign up for a free GitHub account: https://github.com/. Happy Git has good advice on picking a user name.
    • Install Git on your computer using these directions. NOTE: There’s a chance that Git is already installed, so you might skip this step and come back to it if necessary.



  • Create a new GitHub repository. This is like a folder where you’ll store work related to your project.
    • Log onto your GitHub account.
    • In the upper right hand corner, click “+” and then “New repository.”
    • Name your repository.
    • Click “Add a README file” and then click on “Create repository.”



  • Add collaborators (i.e. your group members).
    • Go to your GitHub repository.
    • Click on “Settings” in the upper right corner. This might fall under 3 dots “….”
    • Click on “Manage access” on the left side of the screen.
    • Click the “Add people” button.
    • Search people by their GitHub name.
    • Click “Select a collaborator above.”



  • Create a new RStudio project that’s linked to GitHub.
    • Within RStudio, open a new project and select “Version Control.”
    • Go back to GitHub, click on the green “Code” button, and copy the HTTPS address for your GitHub repository.
    • Back in RStudio, paste the HTTPS into the “Repository URL.” Under “Create project as subdirectory of,” make sure that the project will be stored where you want it (eg: your STAT 454 folder).
    • Finally, click “Create Project.”
    • To work with this project in the future, open the associated .Rproj file.



  • Create a new Rmd / do some analysis. Once you’re ready to share this with your group:
    • Go to the “Git” tab in the upper right panel of RStudio.
    • Locate the file you want to share and check the box. NOTE: Do NOT share any .gitignore file or your .Rproj.
    • Click the “Commit” button above your files then write a brief message about what you’re sharing (eg: data cleaning, model 1, etc). This is a way to communicate with your group members and track changes in the future.
    • Click the “Commit” button.
    • Click the “Pull” button. (This will be discussed next.)
    • Click the “Push” button. This pushes your file / changes to your file to the GitHub repository.
    • Check out your GitHub repository. Your new file / change is there along with your commit message!



  • Once your group member has made changes and pushed them to GitHub, they’ll show up there. To work with these new files / changes, pull these changes into RStudio:
    • Within RStudio, go to the Git tab.
    • Click the down arrow button (which symbolizes “Pull”). This pulls in any new changes / files from GitHub.
    • These changes now show up in your file.



  • Caution with push and pull
    If you and your group members edit the same section of a document at the same time, it can lead to “merge conflicts.” To this end:
    • It’s best to work on different parts of a file.
    • Once you’re done with a certain part of a file, push your changes and hand off to your group members.