Search code examples
gitgitignore

How can I untrack files in Git according to my .gitignore file?


I have tracked many many files early, but I don't want Git to track them any more from now on.

Can I untrack those files according to a .gitignore file?

There are too many files and they are separated in many different directories, so it is not practical to remove them one-by-one, instead, I hope they can be untracked according to patterns in a .gitignore file.


Solution

  • You need to remove the files from the index.

    git rm -r --cached . 
    

    and then add

    git add .
    

    Finally commit:

    git commit -a -m "Untrack ignored files!"