macOS High Sierra下找不到机器级gitconfig文件的原因及查找方法
git config --system --list throws an error on macOS High Sierra (pre-installed Git) First off, don’t worry—this error isn’t a sign your Git installation is broken. Here’s the breakdown:
The pre-installed Git that comes with macOS High Sierra (and most Apple-provided Git versions) doesn’t create the /etc/gitconfig system-level config file by default. This file only exists if it was manually created by you, another user, or an installer that needed to set system-wide Git preferences. The error message is just telling you the file hasn’t been set up yet.
How to handle the system-level gitconfig file:
- Create it manually: If you want to use system-wide Git settings, you can make the file yourself. Run these commands in Terminal (you’ll need admin privileges):
Replacesudo touch /etc/gitconfig sudo nano /etc/gitconfignanowith your preferred text editor (likevim) if you want. - Verify the expected path: To confirm exactly where Git is looking for the system config, run this command—it will show you the path even if the file doesn’t exist:
Even though it’ll throw an error about the missing file, it will still print the path it’s trying to access (which should begit config --show-origin --system user.name/etc/gitconfigfor Apple’s pre-installed Git). - Note on third-party Git: If you ever install Git via Homebrew or another package manager, the system config path might change (usually to
/usr/local/etc/gitconfig), but since you’re using the pre-installed version, stick with/etc/gitconfig.
Remember, your user-level config (~/.gitconfig) works fine because Git automatically creates that file when you set global preferences (like git config --global user.name "Your Name").
内容的提问来源于stack exchange,提问作者Jun Yin

