How to git ignore ipython notebook checkpoints anywhere in repository

GitCommitGitignoreJupyter Notebook

Git Problem Overview


This is mostly a git question. I want to commit my ipython notebooks but gitignore the checkpoints.

The repo has multiple folders which each have ipython notebooks, therefore just ignoring a single directory does not solve it. I want to keep adding new folders with notebooks inside without worrying about it.

My hunch is that there must be a way to use some wildcard to gitignore anything that is in a folder that is called */.ipynb_checkpoints/ but haven't been able to figure it out.

So, how can I git ignore all ipython notebook checkpoints in a repository, wherever they are?

Git Solutions


Solution 1 - Git

If you add to .gitignore:

.ipynb_checkpoints

(no slashes anywhere), any file or directory in the repo with that name will be ignored. Paths are only checked if you include /.

From this answer you can also have a global gitignore for your computer:

git config --global core.excludesfile '~/.gitignore'
echo '.ipynb_checkpoints' >> ~/.gitignore

Solution 2 - Git

I would recommend to use **/*.ipynb_checkpoints/ in your .gitignore file.

Solution 3 - Git

Add to your .gitignore:

.ipynb_checkpoints
*/.ipynb_checkpoints/*

And you should be good to go.

Solution 4 - Git

If you haven't pushed your code yet, add

.ipynb_checkpoints

to your .gitignore

If you have already pushed your code before, add .ipynb_checkpoints to your .gitignore. This will ensure that .ipynb_checkpoints will be ignored in the future but doesn't remove your old .ipynb_checkpoints

You have to manually remove the cache in every folder in the respective branch. Go to the folder that has the .ipynb_checkpoints at first and do

git rm -r --cached .ipynb_checkpoints

Solution 5 - Git

Some times you may forget that you are already tracking the file in your git repository (as it was in my case). So you may have to untrack it first

git rm --cached Folder_with_ipynb/.ipynb_checkpoints/news-checkpoint.ipynb

and then add to your .gitignore the line:

*/.ipynb_checkpoints/*.ipynb

Solution 6 - Git

This works.

Folder/.ipynb_checkpoints/*.ipynb

Solution 7 - Git

For some reason, none of the current answers worked for me. I was eventually able to get git to ignore all of my checkpoint files (and any other unwanted hidden files and folders) by adding:

.*  # ignore all hidden files and folders
!/.gitignore  # explicitly do not ignore .gitignore

to my .gitignore file in the repo's base directory. This is a broad sweep, and will be a pain to maintain if you want to keep hidden files in your repo, but I have no need for any except my .gitignore, so it works for me!

Solution 8 - Git

I used the command rm -rf .ipynb_checkpoints. This worked for me.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionsapo_cosmicoView Question on Stackoverflow
Solution 1 - GitminrkView Answer on Stackoverflow
Solution 2 - GitAnton KarazeevView Answer on Stackoverflow
Solution 3 - GitdjwbrownView Answer on Stackoverflow
Solution 4 - GitAshok KumarView Answer on Stackoverflow
Solution 5 - GitAlexanderView Answer on Stackoverflow
Solution 6 - GitMerlinView Answer on Stackoverflow
Solution 7 - GitEngineeroView Answer on Stackoverflow
Solution 8 - GitSahar NasserView Answer on Stackoverflow