17

I have 3 paths that I'm trying to ignore in my .gitignore file:

aws_scripts/python/aws_tools/__pycache__/
.vscode/
aws_scripts/output_files/
aws_scripts/source_files/

Everything gets ignored except for aws_scripts/python/aws_tools/__pycache__/

git status
On branch develop
Your branch is up to date with 'origin/develop'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   aws_scripts/python/aws_tools/__pycache__/ec2_mongo.cpython-39.pyc

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        .gitignore

no changes added to commit (use "git add" and/or "git commit -a")

If I comment out the lines in .gitignore, those directories are there again in git status. .gitignore with lines commented out:

#aws_scripts/python/aws_tools/__pycache__/
#.vscode/
#aws_scripts/output_files/
#aws_scripts/source_files/

Result in git status:

git status
On branch develop
Your branch is up to date with 'origin/develop'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   aws_scripts/python/aws_tools/__pycache__/ec2_mongo.cpython-39.pyc

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        .gitignore
        .vscode/
        aws_scripts/output_files/
        aws_scripts/source_files/

Why is only the __pycache__ directory not working with .gitignore?

phd
  • 82,685
  • 13
  • 120
  • 165
Tim Dunphy
  • 685
  • 2
  • 10
  • 25
  • 4
    You can't ignore tracked files. – tkausl Jan 15 '21 at 15:13
  • These directories are untracked: `Untracked files: (use "git add ..." to include in what will be committed) .gitignore .vscode/ aws_scripts/output_files/ aws_scripts/source_files/` But they disappear when I add them to `.gitignore` andI do a git status. – Tim Dunphy Jan 15 '21 at 15:18
  • 2
    `aws_scripts/python/aws_tools/__pycache__/ec2_mongo.cpython-39.pyc` is a tracked file, otherwise git wouldn't list it as _modified_. – tkausl Jan 15 '21 at 15:18

1 Answers1

35

Notice the modified in your git status output. That means you already added and commited the __pycache__.

git rm -rf <PATH> it, commit and it should start to be properly ignored.

It is not a bad idea to start with official .gitignores from the beginning and extend those: https://github.com/github/gitignore

Roman Pavelka
  • 3,736
  • 2
  • 11
  • 28