Your file looks good. Just make sure you don't have any kind of whitespace at the beginning of each line, it took me 4 hours to find why my .gitignore wasn't working correctly; the reason was of course a cut'n'paste issue where I had a vertical line of spaces at the beginning of the file.
You should be careful with git commit -a
before making sure that your .gitignore file really cleans out everything you don't want. Either mark each file (or use wildcards) with git add *.cpp *.h
or - like I prefer - develop your .gitignore as you progress, and always check with git status
before commiting.
If you want to double-check that your .gitignore really works, try
git ls-files --others -i --exclude-standard
This should list all the files that you are currently ignoring.
To clean out the files you've already added (probably using git add .
, a mistake we all make in the beginning =]) you can do like @VonC said:
either run
git rm <filename>
or
git rm --cached <filename>
Another option of cleaning out all the files you've unintentionally added is to totally clean your repository, and then re-add everything again. If you want to clear out everything in the staging area, you can run
git --rm cached .
But remember to not run git add .
Until you've made sure that git status only lists the files you really want in the repository.
Another very useful thing with git is that it doesn't need paths to files when using wildcards. If you list your ignored files and see that you want to remove all *.suo
and *.log
files, just run
git rm --cached *.suo *.log
and git takes care of finding all the files in your repository that matches that signature, no matter where in the tree they are.