Damitha.
Lab Notebook
Programming

Introduction to Git and GitHub for Reproducible Research

Why version control matters for research code, and the small set of commands that cover 95% of day-to-day use.

10 September 20262 min read
programminggitreproducibility

A script that produced a result six months ago, with no record of what changed since, is not reproducible - and "reproducible" is not optional in clinical or research software. Git solves this by recording every change as a snapshot you can always return to.

The core idea

Git tracks a project as a series of commits - snapshots with a message describing what changed and why. GitHub hosts those commit histories remotely, so they're backed up and shareable.

The commands that cover most days

# Start tracking a project
git init
 
# See what's changed
git status
 
# Stage and commit
git add analysis.py
git commit -m "Add GC content calculation for QC step"
 
# Connect to a remote repository and push
git remote add origin https://github.com/username/project.git
git push -u origin main
 
# Pull down changes from elsewhere
git pull

Branches - working without breaking main

A branch is an independent line of work. The standard pattern: keep main always in a working state, and do new work on a branch.

git checkout -b add-variant-filter
# ... make changes, commit them ...
git push -u origin add-variant-filter
# open a Pull Request on GitHub to review and merge back into main

.gitignore - keep large/sensitive files out

Git is for code, not data - especially not patient data. A .gitignore file tells Git what to never track:

# .gitignore
*.bam
*.fastq.gz
*.vcf.gz
__pycache__/
.env

This matters twice over in a clinical context: large sequencing files don't belong in a code repository, and patient-identifiable data must never end up in version control (especially if the repository is later made public).

Writing a commit message that's actually useful

Bad:  "fixed stuff"
Good: "Fix off-by-one error in exon coordinate conversion (0-based -> 1-based)"

Six months from now, git log is often the only record of why a change was made - a specific, descriptive message is worth the extra ten seconds.

A brief introduction to Git for beginners - GitHub

Further reading