How to make Git “forget” about a file that was tracked but is now in .gitignore?

You can ignore certain files and folders from being committed to Git by means of including a .gitignore file.

Unfortunately, you may have forgotten to include certain entries and now find that there are files and/or folders that git will want to commit.

To start with, you should make sure that the relative path to the file or folder is included in your .gitignore file.

Then run one of the below commands.

Forget a single file

To do this, you will need to remove the file from the local cache:

git rm --cached <file>

Forget a directory of files

However, if you have a directory of files, then you can forget the files like this:

git rm -r --cached <folder>
0 0 vote
Article Rating
Notify of
Inline Feedbacks
View all comments