I ran across this issue earlier in the week, where I was working in a repository that didn't have a .gitignore. There were multiple directories and files I wanted leave out of the repo, but they were already commited and pushed. After browsing for a solution onStackOverflowon how to remove files from a repo that are now in my .gitignore, I found this solution.

First commit any outstanding code changes, and then, run this command:

git rm -r --cached .

This removes everything from theindex, then just run:

git add .

Commit it:

git commit -m ".gitignore is now working"
You can also remove individual files, if you don't want such a drastic approach:

git rm --cached filename
Then add your changes again, commit, and push.

If you continue to have issues, I recommend navigating to the link at the bottom and see other answers some users had on StackOverflow.