3

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 ?

torek
  • 448,244
  • 59
  • 642
  • 775
MistyD
  • 16,373
  • 40
  • 138
  • 240
  • 1
    Those files are *already in your repository*, and are currently tracked (i.e., in your index). Listing them in `.gitignore` has no effect. You must make them untracked: see https://stackoverflow.com/questions/936249/how-to-stop-tracking-and-ignore-changes-to-a-file-in-git – torek Nov 27 '18 at 09:11

1 Answers1

9

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 .
Mr.Turtle
  • 2,950
  • 6
  • 28
  • 46