Jupyter Notebook .gitignore template
The Jupyter template ignores autosave checkpoints and per user profile directories, and does nothing about the output cells that make notebook diffs unreadable.
At a glance
- Category
- Language
- Patterns in this template
- 5 rules
- Directories ignored
- 3 of the 5 rules end in a slash, so they match directories only
- Also needs an OS template
- Yes. Notebook projects accumulate file manager artefacts in data folders in particular.
- Typical companions
- Python, since a notebook project almost always has a virtual environment and caches too.
In detail
.ipynb_checkpoints is the autosave directory. Every time the editor saves a checkpoint it writes a full copy of the notebook there, so the directory ends up holding a stale duplicate of every notebook in the folder. Both rules in this template target it: the first matches it at any depth, the second matches its contents in a subdirectory, which is belt and braces for older tooling.
profile_default and ipython_config.py hold interactive shell configuration for one user: startup scripts, display settings, extension loads. .virtual_documents is written by editor language server integrations, which extract the code from a notebook into plain files so a language server can analyse them.
The problem this template cannot solve is the notebook format itself. A notebook is JSON containing both your source and the output of every cell, and the output includes execution counts that change on every run, base64 encoded images, and whatever the last run printed. Two people running the same notebook produce completely different files, so the diff is unreadable and the merge conflicts are unresolvable by hand.
The usual answers are to strip output before committing, using a filter that runs on staging, or to pair each notebook with a plain script export and review that instead. Neither is an ignore rule, which is why a repository that only adds this template still ends up with noisy history.
The other risk is what those outputs contain. A cell that printed the head of a dataframe has embedded that data in the notebook file, and a cell that echoed an environment variable while debugging has embedded a credential. Committing a notebook is closer to committing a screenshot of your session than to committing code.
Examples
.ipynb_checkpoints/
*/.ipynb_checkpoints/*
profile_default/
ipython_config.py
.virtual_documents/5 lines exactly as the tool writes them, before any common additions you tick.
Things that catch people out
- No rule here strips cell output. If the notebook itself is tracked, its stored outputs travel with it, including any data or key a cell happened to print.
- The second rule, */.ipynb_checkpoints/*, only matches one directory level deep because of how the leading segment binds. The first rule is the one doing the real work.
- Notebooks in a data directory often sit next to the data. Ignoring the notebook checkpoints does nothing for a large CSV, so add a rule for your data folder as well.
Try it: .gitignore Generator
Pick one or more templates, tick the common additions you want, and copy or download the combined .gitignore.
.gitignore Generator
LOCAL · Browser-OnlyGenerate comprehensive .gitignore files by combining templates for languages, frameworks, IDEs, and operating systems
Language
Framework
IDE
OS
Build Tool
Infrastructure
Common Additions
Preview
Select templates or common additions to generate a .gitignore file.
Related .gitignore templates
All .gitignore templates →Python .gitignore template
A line by line read of the Python .gitignore template: bytecode caches, virtual environments, packaging output, test caches and the lib/ rule that bites.
R .gitignore template
The R template ignores saved workspaces, session history, rendered vignettes and check output, plus the .httr-oauth file that stores live access tokens.
macOS .gitignore template
Where .DS_Store actually comes from, why it appears in folders nobody edited, and what the rest of the macOS template covers on network and removable volumes.
Laravel .gitignore template
The Laravel template ignores environment files, application keys, compiled assets and editor folders, and it is the most secret aware template here.
Node.js .gitignore template
The longest JavaScript oriented template: dependency directories, every package manager's debug log, bundler caches, env files and Yarn Plug'n'Play state.
React .gitignore template
A short template built around one idea: the .env.local family is per developer and never committed, while the plain .env is shared and usually should be.
Tools for this
- .gitignore Generator Generate .gitignore files for any project - 50+ templates for languages, frameworks, IDEs, and OS