Robert Schaap

Blogging like it’s 1999

Personal gitignore file

Everybody should be free to use their own tools and workflow without causing problems for other people. Therefore I always recommend people to maintain a personal gitignore file for rules that are specific to you but not the project.

Prevent clutter

To prevent clutter in a project’s .gitignore file you should move all the rules for files that are not specific to the project but specific to you, your system and your tools into a seperate gitignore file.

Besides reducing clutter it will prevent noisy commits and changes in your project’s history where a new contributor is adding their personal exclude rules to the gitignore file or an existing contributor discovers a new tool. Or perhaps falls out of love with a tool and leaves the project’s gitignore file with rules that nobody actually needs. #FirstWorldProblems

These files to exclude are usually related to the Operating System, IDE or tools you use when working on the project. Some examples of files that should not be checked in but should also not be in the project gitignore file are the .swp files that vim will litter your working directory with. Many IDEs will create files to maintain information about the project’s workspace and settings in folders called .vscode or .idea. Information about virtual environments, depending on the tools you use that means ignoring for instance venv, .envrc or .direnv files.

Files that should be included in your project’s .gitignore file are files that are created when you build your software but should not be checked in. These are usually intermediate and end results that are produced when you build your project.

Instructions

Personally I just create a .gitignore file in my home folder.

$ touch ~/.gitignore

You can choose a different name or location. This is convenient for me because I like to keep it simple and I don’t edit the file very often. This way I don’t have to spend any time searching for it when I do need it.

After creating the file you need to configure git to actually use the file.

$ git config --global core.excludesfile ~/.gitignore

After that you can add new rules to exclude files that are specific to your tools and workflow to your heart’s delight.