How to remove a file from the index?

git rm --cached file_name

To remove a file from the index without deleting the actual file use git rm --cached file_name.

Layer 1
Terminal Example
git rm --cached image.png
rm 'image.png'

git status
On branch main
Changes to be committed:
  (use "git restore --staged ..." to unstage)
  deleted:    image.png

Untracked files:
  (use "git add ..." to include in what will be committed)
  image.png

See git rm to learn more about it.

Last modified on November 30, 2021.

You might also like