Most data scientists learn Git the hard way: after overwriting a good notebook, or after being unable to say which version of the code produced a result. A small set of habits covers most of what you need, and they matter more than knowing every command.
Why version control matters for data work
Data projects change constantly: new features, new splits, new models. Git records each change with a message and a timestamp, lets you return to any earlier state, and lets several people work without overwriting each other. It also ties a result to the exact code that produced it, which is the foundation of reproducibility, along with fixing random seeds as discussed in random seed reproducibility.
The everyday commands
git init # start tracking a project
git status # what changed?
git add src/features.py # stage a file
git commit -m "Add tenure bucket feature"
git log --oneline # history, one line per commit
git switch -c try-xgboost # create and move to a new branch
git switch main # go back to the main branch
git merge try-xgboost # bring the branch's work into main
These eight commands are enough to start. Add git push and git pull when you share the project through a remote service such as GitHub.
Commit small, with clear messages
A commit should do one thing, such as add a feature, fix a bug or change a split, and the message should say what and why. A history of commits named “update” and “final” is nearly as useless as no history. Small commits make it easy to find the change that broke something, and to undo only that change.
Use branches for experiments
A branch is a safe place to try an idea. If it works, merge it. If it does not, delete the branch and your main code is untouched. This suits modeling work, where most ideas fail, and it pairs naturally with tracking each trial, as described in MLflow experiment tracking: log the commit hash with each run and you can always return to the exact code.
What to keep out of Git
A .gitignore file lists what Git should skip. For data projects, that usually means the following:
- Large data files and trained model files, which bloat the repository and are not diff-friendly.
- Virtual environments and cache folders.
- Secrets such as passwords, API keys and credentials. Once committed they stay in the history, so keep them out from the start.
- Personal or sensitive data, a risk covered in PII in data pipelines.
Large datasets and models need a different tool, covered in data versioning.
Notebooks need extra care
A Jupyter notebook stores its code, its outputs and metadata in one JSON file, so a small change can produce a huge, unreadable diff, and outputs may contain sensitive data. Clear outputs before committing, or use a tool that strips them automatically. Better still, move reusable logic into plain Python files that Git handles well and that you can test, as argued in from notebook to data product.
Collaborating
On a team, work on a branch and open a pull request so someone reviews the change before it reaches main. Reviewers can catch mistakes in modeling code, and automated checks, such as the tests in how to test a data pipeline, can run on every pull request.
When things go wrong
Most Git mistakes are recoverable. Before trying anything drastic, run git status and git log to see where you are, and commit or stash your work first. If you committed something you should not have, such as a secret, treat it as exposed: change the secret and ask for help rewriting the history, instead of assuming a later commit hides it.
A quick checklist
- Is the project in a Git repository, with commits that each do one thing?
- Does a
.gitignoreexclude data, models, environments and secrets? - Do you try ideas on branches?
- Are notebook outputs cleared, or the logic moved into scripts?
- Do you record the commit hash with every experiment run?
FAQ
Do data scientists need to learn Git?
Yes. It protects your work, records how results were produced and is expected on almost every team. A handful of commands is enough to start.
Can I store datasets in Git?
Small ones, sometimes. Large datasets and model files make a repository slow and are better handled with dedicated data versioning tools or external storage.
What is the difference between Git and GitHub?
Git is the version control tool that runs on your computer. GitHub is a hosting service for Git repositories that adds sharing, pull requests and collaboration features.

