Sometimes you have a project with some files that don’t need to be tracked in version control. To exclude a file from being tracked in Git, you add it to the .gitignore file. But what if the file you want Git to ignore is already being tracked? Well, a file that’s already being tracked will not be ignored, even if you add it to .gitignore. So, how do we tell Git to ignore it? A few easy steps will do the trick.
Commit any pending changes you may have:
Clear the file from cache and commit again:
Now open .gitignore, add <filename> to it and save.
Stage your changes and commit again:
Test it by modifying the ignored file, then
git status. You should see that the file is not being tracked anymore and you’re good to go.