Setting Up a Global .gitignore

I had this Pyright configuration in one of my projects and didn't want to include this file in the .gitignore. My best buddy, my little brain, suggested me an idea: is there something called a global .gitignore? And the answer was YES, and it's pretty helpful!

Here’s How I Set It Up:

  1. Check if there is a default location for the global gitignore:

    git config --get core.excludesfile

    This command returns the location of the file if one exists. In my case, it didn’t.

  2. Create a file at $HOME/.config/git/.gitignore:

    Write anything you want to in it—a love letter? Why not! But don't forget to save the file.

  3. Set the default location:

    git config --global core.excludeFile $HOME/.config/git/.gitignore

    You’re done!

Wait, There’s an Easy Way Too!

You can also set this up more easily by editing the global Git configuration file directly:

Go to ~/.gitconfig and add or change the excludeFile setting.

See, I just saved you a minute of your life!