gitignore is a very handy tool for ignoring unnecessary files in the project. Most large projects have .gitignore file included. Most small projects would benefit from one too. However, working as a developer on a variety of projects, it’s often difficult to add your own rules to all .gitignore files around. And that’s exactly what I wanted.
I’m using Vim editor for all my coding needs, and I wanted to add Vim swap file and backup file to all .gitignore files. That sounded like annoying, so instead I looked around for a global gitignore solution. As always, StackOverflow has an answer for everything. There is a way to disable extra files in Vim, but there is an even better way to have your own global .gitignore. Here is how to do it:
- Edit .gitconfig file in your home folder, and add excludesfile=~/.gitignore line to the core section.
- Create .gitignore file in your home folder with whatever rules you desire.
Once that is done, all your projects will ignore the files matching the rules. If you are not sure which rules to start with, borrow one of the gitignore files from this GitHub project.