1

I just follow this solution to add __pycache__/ in my .gitignore but it doesn't work. All directory with format __pycache__ still appear in my git status

enter image description here

torek
  • 448,244
  • 59
  • 642
  • 775
NM Naufaldo
  • 1,032
  • 1
  • 12
  • 30
  • 2
    Since it says `modified` for those `__pycache__` directories, that means those files are already committed and tracked in your repo, and adding it to gitignore won't "un-commit" them. – Gino Mempin Feb 15 '22 at 09:25
  • 1
    Or the more general: [How can I make Git "forget" about a file that was tracked, but is now in .gitignore?](https://stackoverflow.com/q/1274057/2745495) – Gino Mempin Feb 15 '22 at 09:26

1 Answers1

6

As you have already committed the pycache/ folders before, when you add it to gitignore it can't ignore them, they have already been pushed. You, therefore, need to remove them from your repository using git rm -r <path to __pycach__> and commit this change. Then the gitignore should work.

Joshua Zeltser
  • 488
  • 2
  • 9