问题描述
Git像往常一样困扰着我
Git is hassling me with the usual
*** Please tell me who you are.
Run
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
我通常会以
git config user.email "me@example.com"
git config user.name "Me Name"
我不希望全局设置上述值,因为我有多个主机,并且希望为每个SSH主机使用不同的Git身份。是否可以将Git身份链接到SSH主机和/或身份,例如通过具有某种通用配置文件
I don't wish to set the above globally as I have multiple hosts and wish to use a different Git identity for each SSH host. Is it possible to link the Git identities to the SSH hosts and/or identities, e.g. by having some sort of common config file
Host github.com
IdentityFile ~/.ssh/github_rsa
user.email "me@example.com"
user.name "Me Name"
Host gitlab.com
IdentityFile ~/.ssh/gitlab_rsa
user.email "another@example.com"
user.name "Another Name"
推荐答案
我没有看到通用的方法,但是可能会有这样的自定义解决方案:
I don't see a generic way for this but there could be a custom solution like this:
创建一个 properties 每个存储用户设置的git服务器的主机名的文件:
Create a properties file with the Name of the host for each git Server that stores the user Settings:
echo 'user.email "me@example.com"' > $HOME/.mygitconfig/github.com.user
echo 'user.name "Me Name"' >> $HOME/.mygitconfig/github.com.user
并创建一个脚本来沿此克隆存储库行(未经测试):
and create a script to clone an repository along this lines (untested):
cat%HOME / bin / clonerepo
#!/user/bin/bash
git clone git@$1/$2 .
while IFS=$'\n' read -r user_data; do
git config $(user_data)
done < $(HOME)/.mygitconfig/$1.user
您使用它:
$HOME/bin/clonerepo github.com path/to/repo.git
这篇关于根据SSH主机或身份指定Git身份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!