是否可以为不同的站点设置全局 git 配置?
Is it possible to have a global git config for different sites?
假设您有这个 git 项目文件夹结构:
- /home/user/gitlab
- /home/user/github
是否可以在一个地方的某个地方定义git使用证书的授权逻辑应该为路径之一下的所有项目配置相应的?也许还有不同的用户签名?
对于访问:您可以使用 ~/.ssh/config
文件为不同的服务器设置不同的密钥。
# in your ~/.ssh/config file :
Host github.com
IdentityFile path/to/github_key
Host gitlab.com
IdentityFile path/to/gitlab_key
设置后,与 github.com
(相应 gitlab.com
)的任何 ssh 交互——例如:git clone git@github.com:repo
、git fetch
、git push
.. . -- 将默认使用 github_key
(resp. gitlab_key
)。
对于 git
配置参数(例如:user.name
和 user.email
),您可以按照@choroba 的建议使用 includeIf
部分(link to docs) :
# in your .gitconfig file :
[includeIf "gitdir:~/github/**"]
path = ~/path/to/github_conf_file
[includeIf "gitdir:~/gitlab/**"]
path = ~/path/to/gitlab_conf_file
并在 github_conf_file
和 gitlab_conf_file
中设置 user.name
和 user.email
值。
假设您有这个 git 项目文件夹结构:
- /home/user/gitlab
- /home/user/github
是否可以在一个地方的某个地方定义git使用证书的授权逻辑应该为路径之一下的所有项目配置相应的?也许还有不同的用户签名?
对于访问:您可以使用 ~/.ssh/config
文件为不同的服务器设置不同的密钥。
# in your ~/.ssh/config file :
Host github.com
IdentityFile path/to/github_key
Host gitlab.com
IdentityFile path/to/gitlab_key
设置后,与 github.com
(相应 gitlab.com
)的任何 ssh 交互——例如:git clone git@github.com:repo
、git fetch
、git push
.. . -- 将默认使用 github_key
(resp. gitlab_key
)。
对于 git
配置参数(例如:user.name
和 user.email
),您可以按照@choroba 的建议使用 includeIf
部分(link to docs) :
# in your .gitconfig file :
[includeIf "gitdir:~/github/**"]
path = ~/path/to/github_conf_file
[includeIf "gitdir:~/gitlab/**"]
path = ~/path/to/gitlab_conf_file
并在 github_conf_file
和 gitlab_conf_file
中设置 user.name
和 user.email
值。