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:
- Update .gitignore by adding the folder/files to be ignored, in this example test.xml will be added.
- Add changes and commit
git add .
git commit -m “Modified .gitignore file”
- Execute the following command to clear git cache for the whole repository
git rm -r –cached .
- 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.