Gitignore is used to untrack files intentionally. It has specific pattern to describe which files to ignore. Good documentation regarding Gitignore has been given here : https://git-scm.com/docs/gitignore
Many time we have case where we mistakenly / intentionally adding files in Git tracking. And later we don't want to track it by any circumstances like database configuration or hiding credentials of production.
I mostly follow below steps to add those important files in gitignore and tell git not to track it anymore :
1) Remove file from git index by git rm --cached [file_name]
2) Commit changes git commit -m "intentionally removed file from git index"
3) Make entry of that file in ~/[project root dir]/.gitignore
4) Now edit the same file
5) Verify same file by git status to check it is not tracked
Hope that helps!!