Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to ignore .pyc extension in .gitignore [duplicate]

Tags:

git

I am trying to ignore all .pyc extensions in the repository my .gitignore file looks like this

.idea
*.rdb
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*.pyc
__pycache__/

however when I do git status. I get information on modified files like this

On branch master
Your branch is up-to-date with 'origin/master'.

Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   .DS_Store
    modified:   .gitignore
    modified:   Device/__init__.py
    modified:   Device/admin.py
    modified:   Device/apps.py
    modified:   Device/migrations/0001_initial.py
    modified:   Device/migrations/__init__.py
    modified:   Employee/__init__.py
    modified:   Employee/__pycache__/__init__.cpython-35.pyc

Notice the last file .pyc is shown as modified and also the foled pycache which is added to .gitignore also gets shown. How do I get git to ignore them ?

like image 960
MistyD Avatar asked Feb 04 '26 23:02

MistyD


1 Answers

It seems like your .pyc file was added before you commited the .gitignore.

Try to first remove everything that is tracked by:

git rm -r --cached .

OR:

git rm -r --cached Employee/__pycache__/__init__.cpython-35.pyc

Now, try:

git add .
like image 182
Mr.Turtle Avatar answered Feb 06 '26 14:02

Mr.Turtle