Prevent a deleted file from being tracked in Git

Often it may happen that you need to delete a file such that it should no longer be tracked by GIT. If you simply delete the file from the file system, git detects that a file has been deleted but it does not get deleted from the commit itself sincs its an unstaged change.

To delete a file from your filesystem as well inform git of this deletion in this commit, you can run

git rm filename

But what if you only want to delete the file from the commit but retain it in your local directory. You can run

git rm --cached filename

Using this, git will be informed that the file no longer needs to be tracked hereafter unless added explicitly. Anyone who now pulls from this branch will have their local file deleted since git will no longer stores information about this file from this commit onwards.


Ryan Sukale

Ryan is just a regular guy next door trying to manage his life and finances.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *