Collaborate via Github

Statisticians Advancing in R
for Data Science

Mehdi Maadooliat, Jaihee Choi and Daniel Cirkovic

Marquette University
STAR-DS - SDSS 2026

Why Version Control?

  • Track and restore changes in code over time
  • Collaborate without overwriting others’ work
  • Revert to earlier working versions if bugs appear

Tools Used:

  • git (local)
  • GitHub (remote)
  • RStudio (IDE)

Example: KNNreg Package Github

Screenshot of Pagerank

Git & GitHub Basics

  • Git: Version control system for your local project
  • GitHub: Cloud platform to share and collaborate

Key Terms:

  • Commit = Savepoint
  • Push/Pull = Send/Receive changes
  • Repo = Project folder

Example: You push your R package to GitHub, allowing your coauthor to edit documentation and submit a pull request.

Installing Git

  • Go to git-scm.com
  • Choose your operating system:
    • Windows: Download .exe and install with default options
    • macOS: Install via Homebrew brew install git or Git installer
    • Linux: Use package manager, e.g.:
  sudo apt install git

Verifying Git Installation

Run this in your Terminal (or Command Prompt):

git --version

You should see something like:

git version 2.43.0

If this works, Git is installed correctly!

Configuring Git Identity

Set your global Git identity:

git config --global user.name "Your Name"
git config --global user.email "you@example.com"

To check the name or email currently set in Git, use these commands:

git config --global user.name 
git config --global user.email 

Creating a New Git-Enabled Project

In RStudio:

  1. File → New Project
  2. Choose: New Directory → R Package (or New Project)
  3. Check the box: “Create a git repository”
  4. Finish project setup

A .git folder is created — this is a Git repo!

Make First Commit

Your project becomes a real Git repository only after the first commit.

Before the first commit:

  • Git is initialized, but no project history exists
  • The branch (main) is not fully established
  • Tools like usethis::git_sitrep() may fail
  • GitHub has nothing to receive yet

In Terminal:

git branch -M main
git add .
git commit -m "Initial commit"

After the First Commit

  • Git creates the first snapshot of your project
  • The main branch becomes fully defined
  • Your project now has version history
  • GitHub can track and store it

The first commit turns an empty Git repo into a real version-controlled project.

Connect GitHub to R (Create PAT)

  1. In R:
usethis::create_github_token()
  1. GitHub will open — generate a Personal Access Token (PAT)
  2. Copy the token (only shown once!)
  3. Back in R:
gitcreds::gitcreds_set()

Paste your token when prompted.

You’ve now authenticated GitHub from R!

Connect to GitHub

Run this in R to create and link a GitHub repo:

usethis::use_github()

This will:

  • Push your project to GitHub
  • Open the new repo in your browser

You can now push/pull changes from RStudio Git tab

Check Setup

Use this helpful diagnostic tool:

usethis::git_sitrep()

This tells you:

  • Whether Git is installed
  • Whether GitHub is connected
  • If PAT is stored

Common Git Workflow

  1. Edit your files
  2. Stage changes
  3. Commit with a message
  4. Push to GitHub
  5. Repeat
git add .
git commit -m "Describe your changes"
git push

What each step means:

  • Stage: select changes to include
  • Commit: save a snapshot locally with a message
  • Push: upload committed changes to GitHub

. . .

Good Commit Messages

“Edit inputs and outputs in function documentation to complete help page for knn_pred()”

  • specific
  • explains what changed
  • useful for future you and collaborators

Common Mistakes:

  • Committing everything without checking

  • Vague messages like “fix” or “updates”

  • Forgetting to pull before starting work

From Version Control to Collaboration

So far, Git has helped us:

  • track changes
  • save project history
  • connect our work to GitHub

But Git is not just for saving files, but also built for collaboration.

Working From an Existing GitHub Repo

When you contribute to an existing project, you first need a local copy of the repository.

 

Clone the repository

git clone https://github.com/username/repo-name.git

This creates a local version of the project, including:

  • all files
  • commit history
  • existing branches
  • Git tracking (.git folder)

Working with Branches

Git branch: a separate “copy” of your project’s code where you can safely make changes without affecting the main version.

Branches let you:

  • Work on features without breaking main code

  • Try experiments safely

  • Collaborate in parallel

Branch Workflow

  1. Create a new branch
  2. Switch to the branch and edit code
  3. Stage and commit changes
  4. Push branch to GitHub
  5. Open a Pull Request (PR)
  6. Review and merge into main
git checkout -b new-feature
# make changes
git add .
git commit -m "Add new feature"
git checkout main
git merge new-feature

Summary of Branching

  • main → stable version of your project
  • branch → experimental workspace
  • merge → combine changes into main

Branching is helpful because:

  • Prevents breaking working code
  • Keeps project history clean
  • Enables review before merging

Github Summary

Daily workflow:

Pull → Edit → Stage → Commit → Push

 

 

For new features:

Branch → Edit → Commit → Push

→ Open Pull Request → Merge

Resources & Further Reading

Thank you!

Questions & Discussion