无法配置 git,缺少 .gitconfig 文件

gar*_*oat 1 git macos bash

当我尝试配置 Git 时,收到以下错误:

$ git config --global user.name "John Smith"
error: could not lock config file /Users/John/.gitconfig: No such file or directory
Run Code Online (Sandbox Code Playgroud)

我的根目录完全缺少一个.gitconfig文件。当我尝试制作新的时,我收到此错误:

$ touch ~/.gitconfig
touch: /Users/John/.gitconfig: No such file or directory
Run Code Online (Sandbox Code Playgroud)

我的 git 位置:

$ which git
/usr/local/git/bin/git
Run Code Online (Sandbox Code Playgroud)

我已经尝试重新安装 Git 几次(运行 OSX Yosemite),但仍然遇到同样的问题。正如有关此问题的一些帖子中提到的,我也找不到任何 .gitconfig.lock 文件。

gar*_*oat 5

So I ended up solving this issue by reading the Customizing Git section of the documentation.


While I could not touch a new .gitconfig file in my root directory as stated above, I read that the first place Git looks for configuration values is in etc/gitconfig (note the lack of a . in the name).

So I created a file called gitconfig inside of the etc directory and filled it in with a sample gitconfig I found online, and added my user information to the top like so:

[user]
  name = John Smith
  email = jsmith@example.com
Run Code Online (Sandbox Code Playgroud)

I was then able to commit as my usual self, however I still don't have a .gitconfig in my root, so I am unable to config Git using git config --global, and must do the configurations manually in etc/gitconfig.