如何配置~/.gitconfig文件而不是单个repo';s.git/config文件?

如何配置~/.gitconfig文件而不是单个repo';s.git/config文件?,git,Git,如何配置~/.gitconfig文件而不是单个repo的.git/config文件 ## use this config if repository belongs to userA@github [user] name = userA email = userA@gmail.com ## use this config if repository belongs to userB@github [user] user: userB

如何配置~/.gitconfig文件而不是单个repo的.git/config文件

## use this config if repository belongs to userA@github
[user]
        name = userA
        email = userA@gmail.com

## use this config if repository belongs to userB@github
[user]
        user: userB
        email: userB@yahoo.com 

## use this config if repository belongs to userC@bitbuck
[user]
        user: userC
        email: userC@hotmail.com

最简单的方法是:

  • 拥有
    userA
    userB
    userC
    本地账户
  • 在各自的本地帐户中克隆每个GitHub repo
  • 使用正确的用户名和电子邮件进行全局设置(
    ~userA/.gitconfig
    ~userB/.gitconfig
    ~userC/.gitconfig
在这种情况下,将不需要配置:
~userA
主目录下的任何repo克隆都将受益于正确的
user.name
user.email


但是,如果您试图在*一个本地帐户下自动执行此操作,则需要编写一些脚本,在本地配置文件
~/repo/gitHubCloneRepo/.git/config
中创建/更新正确的值。最简单的方法是:

  • 拥有
    userA
    userB
    userC
    本地账户
  • 在各自的本地帐户中克隆每个GitHub repo
  • 使用正确的用户名和电子邮件进行全局设置(
    ~userA/.gitconfig
    ~userB/.gitconfig
    ~userC/.gitconfig
在这种情况下,将不需要配置:
~userA
主目录下的任何repo克隆都将受益于正确的
user.name
user.email


但是,如果您试图在*一个本地帐户下自动执行此操作,则需要编写一些脚本,该脚本将在本地配置文件
~/repo/gitHubCloneRepo/.git/config

中创建/更新正确的值,您可以使用文本编辑器编辑
~/.gitconfig
(针对每个用户A、B、C),虽然我认为您可能指的是
user.name
,而不是
user.user
。您可以使用文本编辑器编辑
~/.gitconfig
(针对每个用户A、B、C),但我认为您可能指的是
user.name
,而不是
user.user