LKBEN11672: How to make git forget about a tracked file which should not have been checked in in the first place.


Symptom

Git should forget about a certain file which is traced but shouldn't.

Cause

You made a mistake at first checkin and tracked to much.

Solution

Even after changing .gitignore, a file will be tracked if it was checked in. To make git forget about this file, you can use the following command:

git rm --cached <the_file_git_should_forget_about>

To make a folder untracked you can use:

git rm -r --cached <folder_git_should_forget_about>

Please note that this file will be deleted on other devices after the first "git pull" but not on your local device.

Have fun.

Disclaimer:

The information provided in this document is intended for your information only. Lubby makes no claims to the validity of this information. Use of this information is at own risk!

About the Author

Author: Wim Peeters - Keskon GmbH & Co. KG

Wim Peeters is electronics engineer with an additional master in IT and over 30 years of experience, including time spent in support, development, consulting, training and database administration. Wim has worked with SQL Server since version 6.5. He has developed in C/C++, Java and C# on Windows and Linux. He writes knowledge base articles to solve IT problems and publishes them on the Lubby Knowledge Platform.

Latest update: 04.07.2023