Removing files from the Git

The task – to remove file from the Git (and leave it in the filesystem).

The problem occurs when you commit some file into the Git  accidentally. This file will be under version control even if you put into .gitignore  file. For me it’s often happens with *.iml files.



To solve this problem you need to:

  1. Add file to  .gitignore;
  2. run command git rm --cached _filename_ to remove files from Git control;
  3. run git add -u – this tells git to automatically stage tracked files — including deleting the previously tracked files.
  4. and finally git commit -m "file deletion"

That’s all! Files are removed from Git and still available locally.



Leave a Reply