As your files are not tracked yet, so git is not aware of your files so .gitignore is ignored by git for that first add the files to .gitignore
For adding to .gitignore run the following commands
git rm -r --cached .
git add .
git commit -m "fixed untracked files"
Note: commit your changes or else it will be lost.
For more information please go through the following tutorial to get more info about git: