After adding .gitignore file use following commands
Make sure to commit first your changes you want to keep. The –cached option will keep your files untouched on your disk though.
Other more solution:
Files with space in their paths
In case you get an error message like fatal: path spec ‘…’ did not match any files, there might be files with spaces in their path. You can remove all other files with option –ignore-unmatch:
But unmatched files will remain in your repository and will have to be removed explicitly by enclosing their path with double quotes: