Every time a developer requires to exclude/ignore files and/or folders, in a certain git repository, the .gitignore file becomes handy. However, sometimes git will not exclude files/folders added in .gitignore. The reason is that those resources had been committed before, without being noticed by the developer. In the following example, a new file test.xml has been added, so after executing git status the display will look like this.

Fixing this issue is quite simple by simple using the CLI, just as follows:

  1. Update .gitignore by adding the folder/files to be ignored, in this example test.xml will be added.
  1. Add changes and commit

git add .

git commit -m “Modified .gitignore file”

  1. Execute the following command to clear git cache for the whole repository

git rm -r –cached .

  1. After this, when executing the git status command git will not display test.xml as an untracked file.

From this point, every change to the text.xml will be excluded/ignored.