.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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s