How to git ignore ipython notebook checkpoints anywhere in repository
Solution 1
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
I would recommend to use **/*.ipynb_checkpoints/
in your .gitignore
file.
Solution 3
Add to your .gitignore
:
.ipynb_checkpoints
*/.ipynb_checkpoints/*
And you should be good to go.
Solution 4
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
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
sapo_cosmico
Doing data sciency stuff. When I run into real engineering problems I call an adult.
Updated on November 04, 2020Comments
-
sapo_cosmico over 3 years
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?
-
Engineero almost 7 yearsThis seems like it should work, but for some reason is not working for me. From the root repository folder, my checkpoints are located in
notebooks/.ipynb_checkpoints/
, and I cannot for the life of me ignore them! I tried adding that path, with and without the trailing slash to my .gitignore. I tried your suggestion. I tried adding lots of stars. Any ideas? -
Ciprian Tomoiagă over 6 years@Engineero have you told git where your
.gitignore
file is withgit config
? -
Mr_and_Mrs_D over 6 years@Engineero: have you already commited some of it ?
.gitignore
can't ignore stuff after the fact (if they are already committed) -
Engineero over 6 years@CiprianTomoiaga it is finding my
.gitignore
just fine, and other files and folders will be ignored. I don't know why this doesn't work, but I found something that does. I will add it as an answer. -
Engineero over 6 years@Mr_and_Mrs_D I had that problem too, but I just de-indexed the files and tried something else in
.gitignore
. I was eventually able to make it work with something that I will add as an answer. -
Mr. Unnormalized Posterior over 6 years@Engineero none of the solutions work for me here. Did you get it to work?
-
nishant almost 6 yearsHas anyone found a working solution yet? None of
.ipynb_checkpoints
or*/.ipynb_checkpoints/*
seems to be working -
pebox11 about 5 yearsYes for me too none of the above works. Even what you proposed. When a checkpoint is created it appears in git status.
-
Chandra Kanth about 4 yearsThat is to delete the folder, not ignoring it. This is a misleading answer.
-
Steven C. Howell about 4 yearsUsing
.ipynb_checkpoints
in the.gitignore
file will works as long as none of those files are already in the git history. I was confused why it did not seem to work until I realized someone had already commit checkpoint files. Once I removed those everything worked fine. I simply usedgit rm .ipynb_checkpoints/*
because the files weren't large and I don't care if they are in the history. If I had more time I would go through the process of removing the entire folder from the history. -
pandamonium over 3 yearsI had this problem and looked through the various answers but this one solved it for me. In fact, I found the solution independently first and only saw this when checking. To be clear, if you have persistent files in
git status
even after you include their folder in.gitignore
, check whether these files have previously been committed. The easiest way to do that is with thegit rm
command above. The--cached
flag will ensure you retain a local copy. -
Gero over 2 yearsGreat, this definitely helped me!
-
Gero over 2 years@pebox11 Same for me, it seemed crazily impossible to not have checkpoints, but finally Ashok Kumar's answer about cached files helped me.
-
liakoyras over 2 yearsThis answer is potentially dangerous to new users. Deleting the folder and adding it to .gitignore are two very different things.