After creating a
.gitignore file in your repository and setting patterns to match files which you do not want Git to track, Git starts tracking repository files and respecting the patterns set in the
.gitignore file after you run the
git add command (For example
git add .).
The problem is that if we later make some changes to the
.gitignore file and then just run the
git add command again, the changes made in the
.gitignore file will not take effect.
For example if you later set in the
.gitignore file that you want Git to start tracking a file which you previously set to be ignored, the file will still be untracked if you just run the
git add . command.
This is because, the git cache needs to be cleared. I usually just do this with the
git rm -r --cached . then after I run the
git add . command to apply the
Things to note to do when making changes to .gitignore file
Here are just some points to note when making changes to the
.gitgnore file to ensure Git is always tracking the right files.
- Make changes in
git rm -r --cached .command.
git add .command
git commit -m "Commit message"or just
git commitor continue working.
What is really important here is step 2. And remember to just run
git add . command before doing any commit.
Check ignored files
If you are using PhpStorm, the ignored files and folders will be automatically marked with the a color having #727238 as color code.
Use this tool to see the color and an approximate name for it.
You can also run the
git status command to check if
.gitignore is working as you want.
That is all for now. I hope short article was able to help you.