多个 git 帐户缺少用户名和电子邮件

Multiple git accounts missing username and email

我有工作和个人存储库,想在同一台机器上使用各自的 git 帐户在两者之间切换。我已经在工作回购上设置了 GPG 签名提交,我想在个人回购上设置 ssh 提交并能够在两者之间切换。

但我一直收到这个错误

Author identity unknown

*** Please tell me who you are.

Run

  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"

我的文件夹结构如下:

root
  |_ .gitconfig
  |_ .ssh 
      |_config
      |_mypersonal (ssh key)
      |_mypersonal.pub (ssh key)
  |_ Desktop
        |_ repos (work)
             |_ .gitconfig.work
             |_ workRepos...
        |_ myrepos (personal)
             |_ .gitconfig.pers
             |_ personalRepos...

这些是上面列出的 git 个文件:

# .gitconfig

[includeIf "gitdir:~/Desktop/myrepos/"]
path = ~/Desktop/myrepos/.gitconfig-pers

[includeIf "gitdir:~/Desktop/repos/"]
path = ~/Desktop/repos/.gitconfig-work

[core]
excludesfile = ~/.gitignore
#config

Host *
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/mypersonal
#.gitconfig.work

[user]
        email = mywork@email.com
        name = Me Work
        signingkey = *********************************
[commit]
        gpgsign = true
#.gitconfig.pers

[user]
email = mypersonal@email.com
name = Me Personal

[github]
user = “githubUserName”

[core]
sshCommand = “ssh -i ~/.ssh/mypersonal”

Double-check 在全局配置中声明的路径,并使用:

git config --list --show-origin --show-scope

在每个存储库中。

您可以将您的设置与 process described in this gist 进行比较。


作为 OP C0deJack mentions in :

  • The file name should be .gitconfig-pers
  • The double quotes should be " rather than