What do you think? Discuss, post comments, or ask questions at the end of this article [More about me]

Skip to end of metadata
Go to start of metadata

Problem

Sometimes users complain that .gitignore isn't working - in that they have added specific files to .gitignore but git still identifies these files as having changed when they are about to commit.

Cause

Often the cause is actually due to the user having previously committed said files.  That is, the files are committed to the repo, and hence git is tracking them.  Adding said files to .gitignore after the fact doesn't then have the expected behaviour (basically because the expected behaviour is wrong in this case (smile)).

Solution

A user needs to delete (and commit the deletions) from the branch head before .gitignore will actually ignore the files in question.

An easy way to do this is essentially to remove all local files and then re-add them by executing the following commands from git bash:

git rm . -r --cached
git add .

Then commit with a comment like "removed files that should be ignored".