【问题标题】:Git: Set local user.name and user.email different for each repoGit:为每个 repo 设置不同的本地 user.name 和 user.email
【发布时间】:2017-06-29 06:31:07
【问题描述】:

我目前正在处理 2 个项目,这些项目希望我在向它们推送时使用不同的数据配置我的本地用户名和电子邮件。

为此,我一直在更新我的配置,例如:

git config --local user.email "namelastname@domain.com"

由于它们是不同的存储库,有没有办法可以为每个存储库定义一个本地电子邮件?

也许在.gitconfig

【问题讨论】:

  • repo = 所有分支、所有版本等。所以当你说“因为有不同的分支......我可以为每个 repo 定义电子邮件吗?”这没有意义。你想要什么:每个 repo 的不同电子邮件设置?还是每个分支机构的电子邮件不同?

标签: git github


【解决方案1】:

只需一个仓库:

git config user.name "Your Name Here"
git config user.email your@email.com

对于(全局)默认电子邮件(在您的 ~/.gitconfig 中配置):

git config --global user.name "Your Name Here"
git config --global user.email your@email.com

【讨论】:

  • 以防万一它对其他人有帮助,您可以通过省略最后一部分来检查您当前的设置,例如git config user.email
  • 这对我不起作用:如果我为存储库设置不同的本地名称/电子邮件,那么推送到源仍然会从全局设置中获取凭据——这正是我想要的避免。
【解决方案2】:

您可以通过在终端上打印来确认:

  1. 全球用户:git config --global user.name
  2. 本地用户:git config user.name

【讨论】:

    【解决方案3】:

    我通常倾向于为我的公司项目和个人项目(在 github 上)保留差异名称/电子邮件

    在需要指定用户/电子邮件的 git repo 中运行以下命令

    git config user.name <user-name>
    git config user.email <user-email>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-04-06
      • 2021-12-18
      • 2020-08-09
      • 2019-07-19
      • 2015-10-03
      • 2021-02-16
      • 1970-01-01
      • 2018-04-25
      相关资源
      最近更新 更多