Version Control with Git & GitHub
(Cogswell, n.d.; Git Project, n.d.; Martin and Martin, n.d.; MIT Missing Semester, 2026; The Carpentries, n.d.; Werenbeck-Ueding, 2026)
01
Why Versions?
02
How Git Thinks
03
How Git(Hub) Works
04
Put It into Practice
LECTURE
HANDS-ON
While adjusting the code, you accidentally changed the code that produces
Figure_3.pnginestimate_model_final_v2.R. Running it regenerated and overwroteFigure_3.png.
Two weeks are passing by
Nobody checks Figure 3 as this was seen as finalized.
“Which script produced the current version of Figure 3 — and why did the employment coefficient change? I need to know ASAP before submission.”
The problem is not saving files. It is knowing what changed, why, and by whom.

The common principle: earlier states remain identifiable and retrievable without creating another file called final_v2
Sources: (Chacon & Straub, 2014; Stack Overflow, 2022)
Terminal, VS Code, RStudio, GitHub Desktop, other Git clients and IDEs
Sources: (GitHub, n.d., 2025)
LOCAL: GIT
Git records the project history
OPTIONAL REMOTE
Share and receive Git history
REMOTE: GIT REPOSITORY
A provider hosts another copy
Git creates the history. A remote exchanges it. A hosting platform organizes collaboration.
Sources: (Chacon & Straub, 2014; GitHub, n.d.)
LOCAL LOCAL LOCAL REMOTE
Working files
edit
⇄
Selected changes
choose
⇄
Local history
record
⇄
Remote copy
share
Most work happens locally. The remote is a separate copy for sharing and synchronizing.
Source: (Chacon & Straub, 2014)
Sources: (Chacon & Straub, 2014; GitHub, n.d.)
Before we work with Git, make sure Git is installed and your GitHub account is connected.
Start with terminal commands to understand how Git works
With many commits, an IDE’s Git view may lag. The terminal often stays faster, more flexibel and more useful
Later, use any interface (UI) you find more convenient
GitHub Desktop, VS Code, RStudio, or another Git client. The interface changes; the repository and workflow stay the same
A) GitHub first
Recommended for this workshop
git clone <url>
B) Existing local folder
git init and make the first local commitorigingit init → git remote add origin <url> → git push -u origin main
C) Existing Git repository
git clone <url> → git remote -v
git <command> [options] [arguments]
git
program
push
command
no option
origin main
arguments
git
program
commit
command
-m
option
"Summary"
argument
-m
option
"Details"
argument
git help --all
All installed commands
git <command> -h
Short syntax and option list
git help <command>
Complete local manual
Complete online reference
Sources: (Chacon & Straub, 2014; Git Project, n.d.)
SYNCHRONIZE
fetch origin
pull
push
push origin <branch>
INSPECT
status
diff
log
RECORD
add <file>
commit -m "<message>"
RECOVER
restore <file>
revert <commit>
reset --soft|--mixed|--hard
BRANCH
switch <branch>
branch
merge <branch>
The habit that prevents most mistakes: inspect the state, preview the change, then act
git status“What state is my repository in right now?”
Safe and read-only, run it often!
git fetch“What changed on GitHub, without changing my work?”
git pull“How do I bring remote work into my current branch?”
git diff“What exactly changed?”
git add“Which change belongs in the next commit?”
The first command stages one file.
git add . stages all changes below the current directory
Working tree
↓ git add
Staging area
Proposed next commit
Prefer a specific file over git add . until you know every changed file belongs together
git commit“How do I record the staged snapshot locally?”
git commit: Good Messages“How should the message explain the research change?”
State the research decision in the imperative form. Keep one coherent change per commit
SAMPLE DECISION Restrict baseline sample to workers aged 25+
MODEL SPECIFICATION Add region fixed effects to wage model
REPRODUCIBILITY Document source and construction of AI exposure measure
git push“How do I publish my local commits?”
Sends commits from the current branch to its configured upstream branch
Push does not create a commit
Local repository: main
↓ git push
Remote repository: origin/main
The commit is now shared remotely
Rejected push? The remote probably moved first. Pull, inspect, integrate, then push again. Do not force it
git log“What has been recorded, and on which line of work?”
git restore“How do I undo an uncommitted or accidentally staged change?”
Removes the file from the proposed commit. The working edit remains available
Staging area
↓ git restore --staged
Working tree keeps the edit
CAUTION — CONTENT WILL BE LOST
git restore code/estimate_model.R permanently replaces the uncommitted working edit with the staged version. Preview with git diff first
git revert“How do I safely undo a commit that may already be shared?”
git reset: soft, mixed, or hard“Which parts of the repository should move back?”
DESTRUCTIVE—NOT A NORMAL BEGINNER WORKFLOW
--mixed is the default. --hard discards uncommitted tracked changes
mode branch staging area working tree
--soft move branch keep staged keep files
--mixed move branch reset staging keep files
--hard move branch reset staging discard edits
The repository can store many branches. A branch points to a commit; it is not a copied folder
The working tree normally shows one checked-out branch at a time. New commits advance that branch
Here: robustness-check isolates an alternative exposure measure until review
A conflict is not corruption. Git stopped and asks for your decision
1: Inspect
Open the file named by git status
2: Resolve
Write the intended final text and delete all markers
3: Record
Save and test, then run git add and git commit
git switch“How do I change which branch appears in my working tree?”
git branch“Which local branches exist, and which one is active?”
git push origin robustness-check“How do I publish a new branch for collaboration?”
git merge“How do I integrate another branch into the current branch?”
Choose out of three different exercise tasks.
1.Commit small, interpretable changes
2.Never commit confidential raw data
3.Use .gitignore early
4.Pull before pushing when collaborating
5.Write README files for your future self
6.Most useful commands: status, pull, add, commit, push
“Good habits formed at youth make all the difference.” (Aristotle)
The Art of Keeping Your Changes
RGS Econ Workshop
Blob Branch Clone Commit Delta Diff Downstream Fetch Fork .git Hash Local main Merge Merge conflict origin Pull Pull request Push Remote Repository Tree Upstream
Click a term—or focus it and press Enter.
Repository
A project together with Git’s recorded history and metadata. A repository can exist locally, remotely, or in both places
ai-adoption-wage-employment/ + its hidden .git/ directory
.git directory
The hidden directory that turns an ordinary project folder into a local Git repository. It contains Git’s object database, staging index, references, configuration, and HEAD
Do not edit it manually. Normal Git commands read and update this internal database
Local
Stored on your own computer. Editing, staging, committing, branching, and inspecting history can all happen locally without internet access
Remember: local commits are not yet an online backup
Remote
A named connection to another Git repository, usually on a server. origin is the conventional name created by git clone
GitHub is one possible remote host—not Git itself
Clone
Create a local repository from an existing repository, including its project history, and normally configure the source as the remote origin
git clone <url>
Commit
A recorded snapshot of the staged project content, with an author, time, message, and link to earlier history
Commit records locally; push publishes commits to a remote
Hash / object ID
A compact identifier computed from an object’s type and content. Change the content and Git computes a different identifier
Hashes help Git identify exact objects and detect corruption. They are not encryption and do not make sensitive content private
Diff
A comparison that Git calculates between two states, such as the working tree and staging area or two commits
A diff displays changed lines. It is not the stored form of a commit
Delta
A compact representation of one object’s content relative to another. Git may use deltas inside packfiles to reduce storage
Deltas are a storage optimization, not the main mental model for commits
Blob
A Git object that stores file content without the filename or directory path
Trees connect blob IDs to names and locations in a snapshot
Tree
A Git object that records filenames, modes, and links to blobs or other trees. It represents one directory in a snapshot
A commit points to the root tree for the recorded project state
Branch / branching
A movable name pointing to a line of commits. A branch lets work develop separately without copying the whole project folder
Example: robustness-check
main
A common name for a project’s primary branch. It has no special powers in Git, and projects can choose a different name
git switch main switches to your local main branch
origin
The conventional name for the remote that git clone configures. It identifies another repository’s address, and you can rename it
origin/main is your local record of that remote’s main branch, updated when you fetch. After cloning your fork, origin normally points to your fork
Fork / forking
A personal server-side copy of someone else’s repository, usually created on GitHub or GitLab. Forking is a hosting-platform workflow, not a core Git command
Useful when you cannot push directly to the original repository
Upstream
The repository or branch from which changes flow toward you. In a fork workflow, upstream commonly names the original repository
The word is directional: upstream depends on where you stand
Downstream
A repository or user that receives and builds on changes from an upstream source. It is a relationship, not a special type of Git object
Your fork is downstream of the original project
Fetch
Download new commits and remote branch information without integrating them into your current branch or changing your working files
git fetch is the safe “show me what is new” step
Pull
Fetch remote changes and then integrate them into the current branch. In the beginner workflow this normally means fetch followed by merge
Pull changes local state; inspect first when collaboration is active
Push
Send local commits to a remote repository and update its corresponding branch—if the remote accepts the update
Push does not create the commit; it transfers commits already made
Merge
Combine two development histories. Git may move the branch forward directly or create a merge commit; overlapping edits can require a conflict decision
Merge integrates histories—it does not mean “upload”
Merge conflict
A situation in which Git cannot automatically combine overlapping changes and pauses so a person can decide the correct final content
Conflict markers—<<<<<<<, =======, and >>>>>>>—identify the competing sections. Resolve the content, remove the markers, then stage and commit the result
Pull request
A hosting-platform proposal to review, discuss, and merge changes from one branch into another. It is not the same operation as git pull
Example: propose robustness-check → main for co-author review
Sources: (Chacon & Straub, 2014; GitHub, n.d.)
Support transparent, traceable, and reproducible research workflows
Return to the exact project state used to produce a reported result
Connect a figure or estimate to its code, data state, and assumptions
Preserve why a sample, model, or interpretation changed
Make authorship and responsibility visible across the project history
Return to a known working state without guessing which backup is correct
Test specifications in parallel without overwriting the baseline analysis
Inspect and discuss changes before accepting them into shared work
Let collaborators contribute asynchronously without passing folders around
Mark submissions clearly and help future collaborators understand the project
One machine stores the revisions. Simple, but difficult to share
Standard example: RCS
One authoritative server coordinates every collaborator
Standard examples: CVS, Subversion, Perforce
Every clone contains the project history and can work locally
Standard examples: Git, Mercurial, Darcs
LOGICAL MODEL · SNAPSHOTS
1 · Working file
code/estimate_model.R
An ordinary saved file on disk
→ git add
2 · Index
.git/index
Paths, modes, and object IDs selected for the next snapshot
→ git commit
3 · Object graph
commit → tree → blob
The commit also points to its parent commit(s)
A diff is a comparison—not the commit
git diff compares the working tree, index, or two snapshots and calculates the displayed changes when requested
Physical storage is optimized
Loose objects are compressed. Packfiles combine many objects and may store similar content as deltas to save space
Source: (Chacon & Straub, 2014)
GIT: LOCAL ENGINE
A content-addressed project database
.git/index, .git/objects, .git/refs, and HEAD8f2c1a7… → one exact object
push →
← fetch
Git protocols transfer missing objects and update references
HOSTING PLATFORM: REMOTE
A hosted interface around repositories
Not included automatically: data governance, permission to share, or protection from committing secrets
Sources: (Chacon & Straub, 2014; GitHub, n.d.)
The core workflow is only the starting point. Each block below can support a separate advanced session
REPOSITORY SETUP
COLLABORATION
PROJECT MANAGEMENT
REVIEW & GOVERNANCE
main and release branches?RESEARCH HYGIENE
PRACTICAL DEMONSTRATION
Source: (GitHub, n.d.)
One issue = one clearly described unit of work
1 · QUESTION
Add a regional robustness check
→
2 · ISSUE #12
Scope, acceptance check, context
→
3 · ORGANIZE
Assignee, label, milestone
→
4 · LINK PR
robustness-check addresses #12
→
5 · CLOSE
The reviewed change completes the task
Source: (GitHub, n.d.)
Issues and pull requests remain the work items; a Project supplies structure and views
TABLE
| Item | Status | Priority |
|---|---|---|
| #12 Robustness | In progress | High |
| #15 README | Ready | Medium |
Best for a compact research backlog
BOARD
Ready
#15 README
In progress
#12 Robustness
Done
#08 Clean data
Best for workflow and handoffs
ROADMAP
Best for timing and milestones
Source: (GitHub, n.d.)
GIT REPOSITORY
Files, commits, branches, tags
PULL REQUESTS
Review and discuss proposed changes
DISCUSSIONS
Open-ended questions and decisions
RELEASES
Publish a tagged research snapshot
ACTIONS
Automate checks and repeatable tasks
ACCESS & SECURITY
Roles, branch protection, and alerts
BROWSER & HISTORY
Inspect files, commits, blame, and diffs
Source: (GitHub, n.d.)
Git, Version Control & GitHub