I have a habit of creating not-so-temporary files and folders in git repositories that I don't want to commit but also don't want appearing in git. To avoid this I have set up a global .gitignore file that ignores files and folders of a certain pattern. Namely any file or folder that includes gitignore in its name. This allows me to create files like test.gitignore.sh, query_gitignore.py or sql.gitignore/users.sql.
To do this I have a global ~/.gitignore with the following content:
*gitignore*
!.gitignore
The first line ignores any file or folder that includes gitignore in its name, while the second line adds an exception for the .gitignore files, which of course I still want git to track.
To set this up, you can run the following command:
git config --global core.excludesfile ~/.gitignore
or manually add the following to your ~/.gitconfig:
[core]
excludesfile = ~/.gitignore