1

I configured git with:

git config --global core.excludesFile ~/.gitignore

I added new rules:

*.png *.h5 *.mat

each one on a different line (consecutive lines) then saved.

Then went to my git folder (with my source code, other files etc.). I do git add *, but git still wants to add h5 files!!. Do I have to do something else? How to make git aware of the new ignore rules before git add?

I have read that creating a .gitignore file and running the aforementioned command was enough to force git to be aware of the ignored files in a global way?

SheppLogan
  • 322
  • 3
  • 18

1 Answers1

2

You can remove the git cache and then add all files again

git rm -r --cached .

Add all files again

git add .

And then commit changes

git commit -m ".gitignore is now working"

Note: be aware to commit all your changes before, otherwise you will lose control on all the changed files

See here for more info

UsamaAmjad
  • 4,175
  • 3
  • 28
  • 35
  • ok thanks, but what about the .gitignore file in my home folder? It it supposed to be checked by git before an add or how does it work? I cannot find a clear explanation – SheppLogan Feb 16 '20 at 20:49
  • It seems like you already committed the files and then trying to ignore them – UsamaAmjad Feb 16 '20 at 20:52
  • Machupicchu, you can read about how git ignore files work [here](https://git-scm.com/docs/gitignore), particularly [this part](https://git-scm.com/docs/gitignore#_notes). – Calum Halpin Feb 16 '20 at 20:56