Most researchers have a folder that looks like this: analysis.R, analysis_v2.R, analysis_final.R, analysis_final_REAL.R. That's version control. It just isn't a good one. You can't tell what changed between files, you can't tell which one made Figure 2, and a month later you won't remember either.
Git solves this properly, and you only need a small part of it to get most of the benefit. This guide covers what Git does, the few commands to learn first, and what to keep out. It fits with the articles on reproducible analysis and backing up research data.
What Git does, in one paragraph
Git keeps a history of your project. Each time you reach a point worth remembering, you save a snapshot called a commit, with a short note about what changed and why. You can look back at any snapshot, compare two of them, or return to an earlier one. Nothing about this needs the internet. It all lives in a hidden folder inside your project.
Git and GitHub are not the same thing
Git is the tool on your computer. GitHub (and GitLab, and Bitbucket) are websites that host a copy of your Git project online. People mix them up because they're nearly always used together. Hosting gives you an offsite copy, an easy way to share code with a collaborator or a reviewer, and a place to point to in a paper. Check whether your institution has a preferred or paid option, since some campuses run their own.
The commands to learn first
You can do real work with these. Run them in a terminal, inside your project folder, or use the buttons in RStudio, VS Code, or GitHub Desktop, which run the same commands underneath.
git initturns the current folder into a Git project. You do this once.git statusshows what's changed since your last snapshot. Use it constantly.git add analysis.Rmarks a file to be included in the next snapshot.git commit -m "Fix age filter in cleaning step"saves the snapshot with your note.git loglists the history so far.
Once that feels normal, learn git push and git pull to sync with GitHub, and git diff to see exactly what changed in a file. Branches, merging, and pull requests can wait until you're working with other people.
Write commit messages for your future self
"Update" and "stuff" tell you nothing in six months. A good message says what changed and, if it isn't obvious, why: "Drop participants with missing consent date (per IRB amendment)." Commit when something works or reaches a natural stopping point, not once a week in a huge batch. Small commits are easier to understand and easier to undo.
What to keep out of a repository
This is the part people get wrong, and it matters more for researchers than for most developers.
- Sensitive or restricted data. Anything covered by an IRB protocol, a data use agreement, or privacy law stays out. Git remembers everything, so a file committed once can live in the history even after you delete it. Hosting it publicly makes that far worse.
- Passwords, API keys, and tokens. If one gets committed, treat it as exposed and replace it. Keep secrets in environment variables or a separate config file that's listed in
.gitignore. - Large raw data and big outputs. Git slows down with big binary files. Store data in proper storage and note in a README where it lives.
- Machine-specific clutter such as temporary files, caches, and
.DS_Store.
A .gitignore file lists the files and folders Git should skip. Create it before your first commit, not after. Both GitHub and GitLab offer starter templates for R, Python, and other languages.
How this supports reproducible work
When a result ends up in a paper, note the commit that produced it. A reader, a reviewer, or you in two years can then check out that exact version of the code and rerun it. Pair it with a record of your software versions and a README that explains how to run things, and you're most of the way to a repeatable project. If your work runs on a shared cluster, Git is also the easiest way to move code there and keep it in step with your laptop, as in the walkthrough on your first job on a research computing cluster.
A reasonable first week
Pick one active project, not an old archive. Add a .gitignore, run git init, and make a first commit of the code and README. Commit after each meaningful change for a few days and read your git log on Friday. Then create an empty repository on your host of choice, set it as the remote, and push. That's the whole habit. Everything else builds on it.
If you teach or support researchers
A two-hour hands-on session with a real project beats a slide deck about branching strategies. Start with the five commands, a .gitignore, and a clear rule on what never gets committed. I build and run this kind of session as part of research computing training for small institutions.
Common questions
What is the difference between Git and GitHub? Git is the tool that tracks changes to your files on your own computer. GitHub is a website that stores a copy of a Git project online so you can back it up, share it, and work with others. GitLab and Bitbucket do the same job. You can use Git without any of them.
Do I need Git if I work alone? It still helps. You get a dated history of every change, a way to go back when an edit breaks something, and a clear record of which version of the code produced a given result.
Can I put my research data in Git? Usually not. Git works best with text and code. Large data files make a repository slow, and sensitive or restricted data should never be committed, because removing it from the history later is difficult. Keep data in approved storage and put the code and documentation in Git.
Is a GitHub repository the same as a backup? Not quite. It's an offsite copy of what you've committed and pushed, which is useful, but it doesn't cover your data or anything you forgot to commit. Treat it as one piece of your backup plan.