DEV Community

Cover image for How to gitignore an existing file
Adam K Dean
Adam K Dean

Posted on

How to gitignore an existing file

You have a file which you now want to ignore, such as a compiled css file, but git is already tracking it.

First, add the path to your .gitignore file:

src/path/to/file/style.css
Enter fullscreen mode Exit fullscreen mode

Then, in git bash, we want to clear the cache, so run these commands:

git rm -r --cached .
git add .
git commit -m ".gitignore is now working"
Enter fullscreen mode Exit fullscreen mode

Now push your changes and be free of these bothersome files!

More info: http://stackoverflow.com/questions/11451535/gitignore-not-working

Top comments (0)