Home > Back-end >  .gitignore is not ignoring untracked files
.gitignore is not ignoring untracked files

Time:09-27

I don't understand why my .gitignore file is not working as intended. It is added to my repo. It fails to ignore the __pycache__ subfolders as well as the test.xyz I added to test the .gitignore functionality.

.gitignore Contents:

__pycache__/
src/__pycache__
*.py[cod]
*.csv
**/*.pyc
*.pyc
*.xlsx
*.xyz

What happens when I run git status:

$ git status
On branch main
Your branch is ahead of 'origin/main' by 1 commit.
  (use "git push" to publish your local commits)

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        src/__pycache__/
        tst.xyz

nothing added to commit but untracked files present (use "git add" to track)

Please advise.

Edit:
Here's the folder structure:

repo/
 |
 | src/
 |  | __pycache__/
 |
 | tests/
 |
 | .gitignore
 | LICENSE

CodePudding user response:

After making changes to .gitignore file, you ought to do the following

# git commit -m "before updating gitignore"
git rm -r --cached .
git add .
git commit -m ".gitignore updated"

To test it, try modifying any of the ignored files, run git status and you'll have nothing to commit (working tree clean).

  •  Tags:  
  • git
  • Related