Archive for the ‘git’ Category

.gitignore not working correct

Posted: 21 February 2020 in git

One of the causes of a dysfunctional gitignore file could be the fact that it was added later and someone already committed files that are meant to be ignored. To fix this issue execute the following commands in the git bash console:

git rm -r –cached .
git add .
git commit -m “.gitignore is now working”

The first line unstages and removes the paths to your files from the git index recursively. The second line adds all your files back in but because the .gitignore is present it will not add files that should be ignored. The final line commits all your files back to the index.

The learning is that .gitignore file works only for committed files only when you rebuild the git index.