.gitconfig通常存储在用户中。主目录。
我使用不同的身份为a公司工作,为B公司工作(主要是名称/电子邮件)。如何使用两种不同的Git配置,使我的签入与名称/电子邮件不一致?
.gitconfig通常存储在用户中。主目录。
我使用不同的身份为a公司工作,为B公司工作(主要是名称/电子邮件)。如何使用两种不同的Git配置,使我的签入与名称/电子邮件不一致?
当前回答
另一种方法是使用direnv并为每个目录分离配置文件。例如:
.
├── companyA
│ ├── .envrc
│ └── .gitconfig
├── companyB
│ ├── .envrc
│ └── .gitconfig
└── personal
├── .envrc
└── .gitconfig
每个.envrc应该包含如下内容:
export GIT_CONFIG_GLOBAL=$(pwd)/.gitconfig
而.gitconfig是通常的带有所需值的gitconfig。
这是我在自定义.gitconfig文件中实际拥有的:
[user]
email = my.name@company.com
[include]
path = ~/.gitconfig
这里只有用户。Email将被覆盖,其余配置取自默认的~/.gitconfig。
其他回答
遵循以下步骤:
从系统中找到.gitconfig Windows文件位置:"C:\Users${USER_NAME}.gitconfig" Linux文件路径:“/usr/local/git/etc/gitconfig” 打开.gitconfig文件,并根据您的条件添加以下行 [includeIf“gitdir: D: \ ORG-A-PROJECTS \”) (用户) 约翰·史密斯 email = js@organizationx.com [includeIf "gitdir:~/organization_b/"] (用户) 无名氏 邮箱= jd@organizationy.com
存储库的特定克隆中的.git/config文件是该克隆的本地文件。放置在那里的任何设置只会影响该特定项目的操作。
(默认情况下,git配置修改的是.git/config,而不是~/。Gitconfig -仅使用——global会修改后者。)
你也可以将环境变量GIT_CONFIG指向一个git配置应该使用的文件。与GIT_CONFIG = ~ /。git配置-指定文件的git配置键值。
从git 2.13版本开始,git支持条件配置包含。在这个例子中,我们克隆了A公司在~/company_a目录下的回购,以及B公司在~/company_b目录下的回购。
在.gitconfig文件的末尾,你可以这样写:
[includeIf "gitdir:~/company_a/"]
path = .gitconfig-company_a
[includeIf "gitdir:~/company_b/"]
path = .gitconfig-company_b
.gitconfig-company_a的示例内容(如果可以使用全局ssh密钥,可以省略[core]部分):
[user]
name = John Smith
email = john.smith@companya.net
[core]
sshCommand = ssh -i ~/.ssh/id_rsa_companya
.gitconfig-company_b的示例内容:
[user]
name = John Smith
email = js@companyb.com
[core]
sshCommand = ssh -i ~/.ssh/id_rsa_companyb
另一种方法是使用direnv并为每个目录分离配置文件。例如:
.
├── companyA
│ ├── .envrc
│ └── .gitconfig
├── companyB
│ ├── .envrc
│ └── .gitconfig
└── personal
├── .envrc
└── .gitconfig
每个.envrc应该包含如下内容:
export GIT_CONFIG_GLOBAL=$(pwd)/.gitconfig
而.gitconfig是通常的带有所需值的gitconfig。
这是我在自定义.gitconfig文件中实际拥有的:
[user]
email = my.name@company.com
[include]
path = ~/.gitconfig
这里只有用户。Email将被覆盖,其余配置取自默认的~/.gitconfig。