Topics: Git/GitHub with RStudio
TASK: Write a report on the relationship between income and crime rates in Chicago.
APPROACH: Jane and Sally approach this task differently…
Let’s unpack all of this…
Is a system that records every change you make to your files in a folder (what changed, who made it, and when) and lets you undo mistakes or restore previous versions of your files.
Git is a software that does version control.
You have to track changes manually which be messy and hard to manage, like:
analysis-1.R
analysis-2.R
analysis-final.R
analysis-final-FINAL.R
You can revisit your project’s history and restore earlier versions of a file if needed!
Feature | Git | GitHub |
---|---|---|
What it is | Version control software | Cloud platform for Git repos |
Where it runs | Locally (your computer) | Online (web-based) |
What it does | Tracks changes in your local repo | Stores & shares remote copies |
Collaboration | Not built-in | Pull, issues, code reviews |
Use in RStudio | Git Tab | Connect via setup or terminal |
Repo | Local repo = your folder | Remote repo = copy on GitHub |
Note: we use Git and GitHub via RStudio only. They are also used with other tools like GitHub Desktop, terminal, etc.
We’ll go through it in two steps:
1. Configure your Setup: Set up Git, GitHub, and RStudio so everything works together
2. Try It Out in RStudio: Git & GitHub tutorial to practice using version control in RStudio
Work in pairs: one person (the most experienced with programming) read the instructions and guide the other, who executes the commands.
Keep track of your questions as you go and post them in this Google doc
Raise your hand if you need help!
Make & Save Changes Locally
Edit your files locally (e.g., in RStudio or Workbench) and save them.
Pull from GitHub
Refresh your local copy to get the latest changes—helps avoid conflicts when collaborating.
Stage Changes
Select which files you want Git to track in the next snapshot.
Commit with a Message
Save a snapshot of your staged changes in your local Git repo. Add a short, meaningful message.
Push to GitHub
Upload your committed changes to the online repository.
Important
You will complete this workflow for all homework assignments!
Stage and commit often
Think of commits as snapshots of your work. Save, stage, and commit regularly during your workflow.
Write clear, useful commit messages
Keep messages concise but descriptive. They should explain what changed and why. Many tips online for “commit message best practices.”
Push regularly, but not necessarily every time you commit Some people push every time they commit, while others push multiple commits at once. Experiment and find what works best for you.
Work locally, and push on GitHub
Do not do the other way around (e.g., do not modify your GitHub repository directly; work on your local copy, and push changes to GitHub).
Accept Homework 1 from the course site and follow the instructions.
Note: this will only work if we have your GitHub username and you accepted the invite to our GitHub organization (which was sent to the email linked to your GitHub account)!
Come back here once you are familiar with the basic workflow! These slides won’t be included in the in-class quiz, but they might be handy if you run into problems in homework assigments.
.Rproj.user/
)What if you need to track a file larger than 100 MB?
GitHub does not allow pushing files over 100 MB. If you have such a file, don’t try to push it directly.
Instead:
A Git conflict happens when Git doesn’t know which version of a file to keep.
Git gets confused because the same file was changed in two places.
Git conflicts are more common when working in shared repositories, and they shouldn’t occur when you’re working alone in your own repository (as you will in this course), but they still can happen…
Collaborative Work
- You and a teammate edit the same file (or even the same line)
- You push changes without pulling the latest version from GitHub first
- Tip: Always run git pull
before git push
Working Solo
- You make changes locally and also edit the same file directly on GitHub
- Git can’t tell which version to keep
- Tip: Always work in your local repository and use the workflow from the previous slide to push to Github
A Git conflict may happen when Git finds two competing versions of the same file: one in your local repo (Git, on your computer) VS. one in the remote repo (GitHub, online)
The local and remote repos are expected to match. If they don’t, Git tries to merge them automatically.
✅ No conflict:
If the changes are in different parts of the file, Git merges automatically and no action is needed.
❌ Conflict:
If the same part of the file was changed in both versions, Git cannot decide what to keep.
→ You must manually review and resolve the conflict.
When a conflict happens, Git marks the file with special lines to show the two versions:
<<<<<<< HEAD
This is your version (from your local repo)
=======
This is the other version (from GitHub or your teammate)
>>>>>>> main
To solve it, you need to use Git with the terminal (ask us for help if that occurs!)
git pull
→ make changes → git add
+ git commit
→ git push
Click on the icon bottom-right corner > Tools > PDF Export Mode > Print as a Pdf