Skip to content

Instantly share code, notes, and snippets.

@maurolepore
Last active August 19, 2022 07:42
Show Gist options
  • Save maurolepore/cc966a117fe53d87f05d0158fde649c2 to your computer and use it in GitHub Desktop.
Save maurolepore/cc966a117fe53d87f05d0158fde649c2 to your computer and use it in GitHub Desktop.
gitforget, How to make Git “forget” about a file that was tracked but is now in .gitignore?

How to make Git “forget” about a file that was tracked but is now in .gitignore?

git rm --cached -r .
git add .
git update-index --assume-unchanged
git commit -a -m "forget cached"

STEP BY STEP

http://stackoverflow.com/questions/1274057/how-to-make-git-forget-about-a-file-that-was-tracked-but-is-now-in-gitignore

Remove all cached files to ensure there are no .gitignore files being tracked

git rm --cached -r .

Track the files that should be tracked

git add .

Very important adding. If file that is ignored would be modified (but in spite of this should be not committed), after modifying and executing git add . it would be added to index. And next commit would commit it to repository. To avoid this execute right after all that mataal said one more command:

git update-index --assume-unchanged <path&filename>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment