Git and GitHub for Researchers: Version Control Your Work Without Fear

A complete guide to using Git and GitHub for research code, data scripts, and even your thesis — explained for researchers with no programming background required.

Git repository showing clean commit history for a research project

You’ve lost work before. A hard drive failure, a file accidentally overwritten, a script that worked yesterday that doesn’t today and you have no idea what changed.

Git solves all of these. It’s a version control system — a way of saving the full history of changes to files so you can always go back, identify what changed, and collaborate without conflicts.

This guide is written for researchers who have never used Git and don’t plan to become developers. You need 3 commands to do 95% of what Git does in research contexts. We’ll have those 3 commands working in under an hour.

What Git Actually Does

Git watches a folder (a “repository” or “repo”) and records every change you explicitly save, along with a message describing what changed.

The result: instead of thesis_FINAL_v3_real.docx, you have a single thesis.md file with a history that looks like:

March 9  — Completed methodology chapter, 4,200 words
March 7  — Added dataset validation section
March 5  — Restructured results section: before/after saved
March 3  — Initial commit

At any point you can go back to any of these versions. You cannot accidentally delete this history.

GitHub is a website where you can store your Git repositories online — giving you a backup and enabling collaboration.


Installation and Setup

Step 1: Install Git

Windows: Download from git-scm.com and run the installer. Accept all defaults.

Mac: Open Terminal, type git --version. If not installed, macOS will prompt you to install it. Accept.

Linux: sudo apt install git (Ubuntu/Debian) or sudo dnf install git (Fedora).

Step 2: Set Your Identity

Open Terminal (Mac/Linux) or Git Bash (Windows) and run:

git config --global user.name "Your Name"
git config --global user.email "your.email@university.edu"

This identifies you in the commit history. It does not make anything public.

Step 3: Create a GitHub Account

Go to github.com and create a free account. You get unlimited private repositories for free.


The 3 Commands You’ll Use 95% of the Time

git add — Stage your changes

Tells Git which files you want to save in the next snapshot.

git add filename.py          # add one file
git add .                    # add all changed files

git commit — Save the snapshot

Creates a permanent record with a message.

git commit -m "Add data validation script"

Write commit messages like this

“Add X” / “Fix Y” / “Revise Z section” — present tense, specific. Bad: “update” or “changes”. Good: “Fix encoding error in CSV parser” or “Complete results section 3.2”.

git push — Upload to GitHub

Syncs your local history to GitHub.

git push

That’s genuinely most of what you need for day-to-day research version control.


Practical Setup: Version Control Your Research Scripts

Creating Your First Repository

# Navigate to your project folder
cd ~/research/my-project

# Initialise Git tracking
git init

# Add all existing files
git add .

# Create the first snapshot
git commit -m "Initial commit: data analysis scripts"

Connecting to GitHub

  1. Go to github.com, click “New repository”
  2. Name it (e.g., phd-analysis-scripts)
  3. Choose “Private”
  4. Do not initialise with README (you already have files)
  5. Copy the provided commands
git remote add origin https://github.com/yourusername/phd-analysis-scripts.git
git push -u origin main

Your code is now backed up on GitHub.


The Workflow That Actually Saves Time

Here is the daily Git workflow I recommend to researchers:

At the start of a work session:

git pull    # get any changes (if you work on multiple computers)

While working: just work normally. Edit files, run scripts.

At the end of a meaningful change:

git add .
git commit -m "Describe what you completed"
git push

You don’t need to commit every 10 minutes. Commit when you’ve completed something: a function, a section, a working analysis step.


What to Version Control (and What Not To)

Do version control:

  • Analysis scripts (.py, .R, .m)
  • Thesis chapters (as Markdown or LaTeX)
  • Data processing pipelines
  • Configuration files
  • Documentation

Do NOT version control:

  • Large data files (use cloud storage or Git LFS)
  • API keys or passwords (use a .env file excluded via .gitignore)
  • Generated files that can be reproduced from scripts

The .gitignore File

Create a file called .gitignore in your repository root to exclude files Git should ignore:

# Data files (too large)
data/raw/*.csv
data/raw/*.xlsx

# Generated outputs
output/figures/*.png
__pycache__/
*.pyc

# Sensitive files
.env
secrets.txt

# OS files
.DS_Store
Thumbs.db

Undoing Mistakes

The most valuable thing Git does for anxious researchers: you can undo almost anything.

“I changed a file and want it back to the last commit”:

git checkout -- filename.py

“I committed something wrong and want to undo just that commit”:

git revert HEAD    # creates a new commit that undoes the last one

“I want to see what changed in a specific commit”:

git show <commit-hash>    # copy the hash from git log

Collaborating with Your Supervisor

If your supervisor wants to see your code:

  1. Add them as a collaborator: repository Settings → Collaborators
  2. They can view, comment, or edit
  3. Pull requests let you propose changes and discuss before merging

For most supervisor relationships, simply sharing the GitHub repo URL is sufficient. They don’t need to know Git to read your code.


GitHub Desktop: If You Prefer Visual Tools

GitHub Desktop is a free application that does everything above through a visual interface instead of the command line. If the terminal feels like a barrier, use it. You’ll do the same operations with buttons instead of commands.


Next Steps

With Git running, the logical next step is learning to write Python scripts that are worth version controlling. See the companion article: Python for Researchers: 10 Scripts That Save Hours →