Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ignore the same name directory __pycache__ in a project?

Tags:

git

gitignore

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?

like image 722
marlon Avatar asked May 25 '19 22:05

marlon


People also ask

Can I delete __ Pycache __ folder?

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)

What is __ Pycache __ folder for?

__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.

How do I ignore a folder in Gitignore?

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.


3 Answers

__pycache__/. The ending slash indicates it is a directory and will ignore any files beneath it.

like image 151
marsheth Avatar answered Oct 06 '22 22:10

marsheth


Use **/__pycache__/ this to ignore all pycache folder across the repo

like image 29
ALPHA-ALI Moise Moustapha hyme Avatar answered Oct 07 '22 00:10

ALPHA-ALI Moise Moustapha hyme


I used this command in my root directory and it worked for me

git rm --cached */__pycache__/*
like image 2
Neerajram19 Avatar answered Oct 06 '22 22:10

Neerajram19