遵循this SO post和链接指南,我设置了如下条件配置...
$ cat ~/.gitconfig
[user]
name = Random J. Hacker
email = RandomJ@hack.er
[includeIf "gitdir:~/work/*"]
path = ~/work/.gitconfig
$ cat ~/work/.gitconfig
[user]
name = Serious Q. Programmer
email = serious.q@programmer.biz
Run Code Online (Sandbox Code Playgroud)
这样,我在 Programmer Co. 工作时克隆的所有存储库都将我的@programmer.biz工作电子邮件地址分配为默认--author凭据;我克隆到我的桌面或/tmp/~/.vscode或任何地方的每个随机存储库都将我的超级合法@hack.er凭证分配为作者。
不幸的是,我注意到以下行为......
$ git clone git@github.com:programmerbiz/repo.git
$ cd repo/
$ git config --list | grep user
user.name=Random J. Hacker
user.email=RandomJ@hack.er
user.name=Serious Q. Programmer
user.email=serious.q@programmer.biz
Run Code Online (Sandbox Code Playgroud)
不好了!我的@hack.er用户被业务回购接收了!
我想为所有 repos自动配置一个且只有一个默认值[user],而无需求助于 bash 脚本。是否有我可以使用的includeIf.Not运算符、[else]块语法或类似方法~/.gitconfig来实现此目的?该条件包括文档似乎并不支持这种使用情况。
的输出是什么git config --list --show-origin | grep user?
您应该看到配置的定义位置。
我想为所有存储库自动配置一个且仅一个默认[用户]
在这种情况下,删除所有上述用户配置并在全局配置中设置一个条目
# Use the `--global` to store it under your user account configuration
# and it will be used as the default for all of your projects unless you
# define it in your local `.git/config`
git config --global user.name <....>
git config --global user.email <....>
----
# For specific project use the `--local` flag (will be stored in your `.git/config`
git config --local user.name <....>
git config --local user.email <....>
Run Code Online (Sandbox Code Playgroud)