0

I have been trying a lot of different commands but nothing seems to be working to Git ignore all the __pycache__ folders and their files in my project. I have written the following code in my .gitignore file and need help to ignore all __pycache__ in any subfolder of my Django project:

**/__pycache__/**

frontend_react_app/node_modules/
frontend_react_app/build

Thanks

torek
  • 448,244
  • 59
  • 642
  • 775
aman
  • 307
  • 21
  • 48

1 Answers1

2

You can simply use:

__pycache__/

Note that if the files are already tracked in a commit, you need to also follow the directions in: How do I make Git forget about a file that was tracked, but is now in .gitignore?

ruohola
  • 21,987
  • 6
  • 62
  • 97
  • I have edited my `.gitignore` with your code but in my VS Code - Source Control tab, some modified `.pyc` files in the `__pycache__` folders are still appearing. Is it not ignoring them or because they already are in my committed repo, they will always be appearing? – aman Jul 21 '22 at 10:50
  • Did you run `git rm -r --cached path/to/__pycache__`? Note the `-r` flag. – ruohola Jul 21 '22 at 11:13
  • So in order for the gitignore to work, I need to delete all the `__pycache__` folders in my git repo online? – aman Jul 21 '22 at 11:15
  • No. You simply run the `git rm -r --cached` command locally, commit the changes and push. – ruohola Jul 21 '22 at 11:51