How to remove file(s) from your remote repository that were added to the .gitignore file AFTER pushing.
I ran into an issue recently where I was setting up WordPress to be managed locally and pushed to the remote server. In doing so, I had to set up a .gitignore file to ensure that many of the always changing WordPress files were not tracked. I pushed up my local repo and noticed that many of my unused themes were still tagging along and this was undesirable.
After some ‘Googling’ I was coming up empty handed and found that the way to do it is to run this command:
git ls-files -i --exclude-from=.gitignore | xargs git rm --cached
This command will successfully clear out the files from your .gitignore file from the remote repository. You may need to go ahead and commit and push your local code to see the changes take effect but this wound up working for me.