shou2017.com
JP

Applying .gitignore Globally

Thu Sep 19, 2019
Sat Aug 10, 2024
Git

This method is only for macOS, so Windows users should look up the specifics elsewhere.

Environment

  • macOS Mojave 10.14.6

Procedure

Git config settings have three levels: system-wide (system), user-wide (global), and repository-specific (local). In this case, we’ll configure the system settings.

On Mac, the gitconfig path is as follows:

| OS | gitconfig path  
|:-----:|:-----:|
| Mac |/usr/local/git/etc/gitconfig|

In this gitconfig file, write what you always want to ignore:

 [core]
    excludesfile = /Users/your_user_name/.gitignore_system

Once the setting is properly configured, it will show up in the list:

$ git config --system --list
core.excludesfile=/Users/Username/.config/git/.gitignore_system

If there’s no git folder in the hidden .config folder in your home directory, create one, and then create a .gitignore_system file inside it. In this file, write what you always want to ignore.

In my case, I only include basics like macOS, IntelliJEDEA, and VisualStudioCode.

macOS

IntelliJEDEA

VisualStudioCode

Clearing Git Cache

When changing Git settings, sometimes the cache may retain old settings, so it’s a good idea to clear the cache.

Remove unnecessary files:

$ git rm -rf --cached .
$ git add .

改訂2版 わかばちゃんと学ぶ Git使い方入門

See Also