1

If I have a repo with files that were previously not in my .gitignore file that I now want to ignore, how do I do this without deleting the files locally and when you pull from the repo?

Jamie
  • 1,909
  • 3
  • 22
  • 47
  • 1
    Does this answer your question? [How to make Git "forget" about a file that was tracked but is now in .gitignore?](https://stackoverflow.com/questions/1274057/how-to-make-git-forget-about-a-file-that-was-tracked-but-is-now-in-gitignore) – phd Jan 29 '20 at 07:15

1 Answers1

2

git rm --cached somefile will preserve the local copy of the file but make git stop tracking that file. Once you do that, you can add the file to .gitignore too.

Paolo
  • 21,270
  • 6
  • 38
  • 69
Mureinik
  • 297,002
  • 52
  • 306
  • 350
  • Yes, but when I pull from the repo the files get deleted. – Jamie Jan 29 '20 at 07:17
  • Yep, that's unavoidable. Even if you just switch to a different branch and then back the file will be removed. – phd Jan 29 '20 at 08:26