Back to blog
Apr 30, 2024
2 min read

Configuring a .gitignore Globally

Setting a global `.gitignore` helps keep commonly generated files from cluttering up any repository.

Visual Studio Code Explorer

Photo by Gabriel Heinzer on Unsplash

Git provides the option to set a global .gitignore file, which applies to all repositories on your system. This can be useful for ignoring commonly generated files like system-specific or editor-specific files that you don’t want to commit to any repository. Here’s how to create a global .gitignore:

Create the Global Ignore File

Choose a location to save your global .gitignore file. For example, you might create one in your home directory (~/.gitignore_global).

Add Patterns to the Global Ignore File

Add the file patterns you want to ignore globally. Common examples include editor backup files (*.swp, *.swo, .bak), system files (.DS_Store, Thumbs.db), and temporary files (.tmp). Or you could take a look at my .gitignore_global file.

Configure Git to Use the Global Ignore File

Open a terminal and set the global ignore file in Git:

git config --global core.excludesFile ~/.gitignore_global

Verify the Configuration

To confirm that the global ignore file is set, use the following command:

git config --get core.excludesFile

It should return the path to your global ignore file.