V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
git
Pro Git
Atlassian Git Tutorial
Pro Git 简体中文翻译
GitX
MasterCai
V2EX  ›  git

如何给每个单独的 repo 配置不同的 GitHub 账号?

  •  1
     
  •   MasterCai · 2021-11-25 20:41:50 +08:00 · 1824 次点击
    这是一个创建于 854 天前的主题,其中的信息可能已经有所发展或是发生改变。

    以前在本机上配置了一个 GitHub 账号,当时是跟着一些教程配的,应该是全局的(--global),现在因为一些原因,给某一个项目单独开了一个 GitHub 账号,但是在 pull 的时候一直显示** remote: Permission to user/repo denied to "之前的用户" **.根据一些教程在当前这个项目下配置了git config user.emailgit config user.name,但是还是有这样的错误。 想问一下应该怎么配置才能达到“全局 github 默认使用之前的账户,在特定项目可以单独配置一个 GitHub 账户”的效果呢?

    8 条回复    2021-11-26 10:42:16 +08:00
    ysc3839
        1
    ysc3839  
       2021-11-25 20:52:13 +08:00 via Android   ❤️ 1
    在 remote url 里加上用户名,比如 https://[email protected]/github/.github.git
    hlwjia
        2
    hlwjia  
       2021-11-25 21:04:32 +08:00   ❤️ 2
    .git 目录里有个 config 文件

    然后你去 google 一下就知道怎么弄了
    stardust21
        3
    stardust21  
       2021-11-25 21:19:49 +08:00   ❤️ 1
    在当前 repo 目录再 config 一下就行,优先级比全局的高
    MasterCai
        4
    MasterCai  
    OP
       2021-11-25 21:23:05 +08:00
    感谢,解决了 原来`git config user.email`并不会改变实际提交的 GitHub 账户
    xarthur
        5
    xarthur  
       2021-11-25 21:35:59 +08:00 via iPhone
    你既然知到—global 是全局,那么自然有个—local
    MasterCai
        6
    MasterCai  
    OP
       2021-11-25 21:54:33 +08:00
    @xarthur 用了-- local 和-- system 都没有效果啊 还是直接改 remote url 这个方式好
    Buges
        7
    Buges  
       2021-11-25 22:21:15 +08:00 via Android   ❤️ 1
    用--local 选项为单个 repo 配置 profile 。
    注意如果你在向某些可能影响到人身安全的 repo 提交代码时,一定要在 commit 之前设置! push 前一定要先在本地检查历史是否有泄漏个人信息。
    如果已经不小心用其他 profile 提交过,安全起见考虑删库重建。
    建议全局选项配置一个 [email protected] 这种假的 profile ,然后为单独每个 repo 用--local 配置。或者也可以利用 conditional include 为某个子目录下的所有 repo 配置。
    killerirving
        8
    killerirving  
       2021-11-26 10:42:16 +08:00
    git config 可以配置指定目录使用指定的 config ,详见 includeIf 配置项
    https://git-scm.com/docs/git-config#_example
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   957 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 20:37 · PVG 04:37 · LAX 13:37 · JFK 16:37
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.