Fix it! Git ignoring contents of .gitignore / .gitignore not working

I’ve had this happen a couple of times when setting up a WP Engine site locally. Ultimately, when trying to push to production an error gets triggered, .git fails to ignore wp-config.php inspite of .gitignore telling it to.

I found a fix (that has worked wonders so far) here.


$ git rm -r --cached .
$ git add . 
$ git commit -m "gitignore is now working"
$ git push
$ git push production