W3docs

How to Make Git Forget About a Tracked File Which is Now in .gitignore

Read this git tutorial and learn how you can force Git to forget about a file that was tracked but is now in .gitignore list.

You may encounter situations when there is a file that was being tracked by Git, but now it is on the .gitignore list. However, if you run git status, it keeps showing the file after it is edited.

Steps to removing the file from Git

Now let’s see what steps you need to make Git completely forget about that file that was tracked but now listed in <kbd class="highlighted">.gitignore</kbd>:

  1. Removing the file from the index

As Git will continue to track any files that are already being tracked, you should remove the file from the index to stop tracking it:

Remove cached files

git rm --cached <file>
  1. Tracking other files

Track the files that should be tracked:

Git add

git add .
  1. Committing the changes

To permanently remove the file from the repository, commit the staged changes:

Git commit

git commit -m "Remove <file> from tracking"

Tracked, Untracked and Ignored Files

Git accepts three kinds of files: tracked, untracked, and ignored. Ignored files are the ones that are ignored by Git. Tracked files are the files that were in the last snapshot. They can be unmodified, modified, or staged. Untracked files are the files in your working directory that were not in your last snapshot and are not in your index.