The __pycache__
directory is annoying when working with git updates. Whenever I use git status
, a lot of .pyc files show up. How can I conveniently list the __pycache__
folder in my .gitignore
file so that they won't show up when using git status
?
For example:
core/__pycache__/utils.cpython-36.pyc
core/__pycache__/version.cpython-36.pyc
core/actions/__pycache__/__init__.cpython-36.pyc
core/actions/__pycache__/action.cpython-36.pyc
Do I have to list all the individual __pycache__
files into the gitignore file?
Explains: First finds all __pycache__ folders in current directory. Execute rm -r {} + to delete each folder at step above ( {} signify for placeholder and + to end the command)
__pycache__ is a directory that contains bytecode cache files that are automatically generated by python, namely compiled python, or . pyc , files. You might be wondering why Python, an "interpreted" language, has any compiled files at all.
If you want to maintain a folder and not the files inside it, just put a ". gitignore" file in the folder with "*" as the content. This file will make Git ignore all content from the repository.
__pycache__/
. The ending slash indicates it is a directory and will ignore any files beneath it.
Use **/__pycache__/
this to ignore all pycache folder across the repo
I used this command in my root directory and it worked for me
git rm --cached */__pycache__/*
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With