Do you also suffer from the fact that when you change your .gitignore file it does not affect already tracked files? Well, here I will show you how to solve that!

How I fixed my .gitignore is being ignored issue

On bitbucket, I got this message that my repository was growing bigger than 2GB. So I went out to analyze which files were actually in the repository. To my surprise, it showed that I had my iOS builds in the repository. A quick check on my .gitignore file showed me that I actually forgot to exclude the build folder.

Stupid mistake. Easy fix. After I updated the .gitignore file so that it excluded the builds folder, I saw that changes to the build folder were still part of my commits.  Apparently, files already tracked previously stay in the repository. Fortunately, there is a trick to tell git to reset the tracked files.

This is what I did to reset my tracked files

First of all, I have updated my .gitignore file so that my builds folder was excluded. After that, I entered the commands below in a terminal window. Make sure you are already inside your project folder!
The steps consist of first removing all files from being tracked without altering them. Next, I add them again and finally commit them again. That’s it!

git rm -r --cached .
git add .
git commit -m ".gitignore fix"