Skip to content

Remove file from Git without deleting locally

If you find yourself in a position where you have already committed some files to git, and they are in the remote repository already, but you want to remove them from you repository without deleting them locally, you can do the following:

Introducing the git rm --cached command:

Remove a folder from Git

git rm --cached -r FolderName

Remove a file from git

git rm --cached SomeFile.ext

And then what?

Now that the files have been removed from the local git cache, you should probably either commit the changes you’ve made, or add an entry to your local .gitignore file and then commit the changes.

This will make sure that it does not happen again.

See also  Calculating Cartesian Neighbors Distance in Golang
Notify of
Inline Feedbacks
View all comments
Would love your thoughts, please comment.x