【问题标题】:Github multiple repositories defaulting to old usernameGithub 多个存储库默认使用旧用户名
【发布时间】:2019-11-07 14:50:45
【问题描述】:

我以正确的方式配置了所有设置,但 git 仍然默认使用不正确的用户名。

我在 git config 中有以下设置:

alias.hist=log --pretty=format:"%h %ad | %s%d [%an]" --graph --date=short
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
remote.origin.url=git@github.com:CORRECT_USER/project
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master
user.email=ID+CORRECT_USER@users.noreply.github.com
user.name=CORRECT_USER

而且看起来不错。

我的 /.ssh/config 也有:

Host github.com-CORRECT_USER
    HostName github.com
    User CORRECT_USER
    IdentityFile ~/.ssh/CORRECT_USER_KEY

所以看起来也不错。

但是,当我...

git push 

我明白了:

ERROR: Permission to  denied to TOTALLY_DIFFERENT_WRONG_USERNAME.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

git 尝试使用正确的用户名和正确的 ssh/config 使用 TOTALLY_DIFFERENT_WRONG_USERNAME 推送正确的 repo,发生了什么?应该在哪里设置?如何取消设置?

【问题讨论】:

    标签: git github ssh public-key


    【解决方案1】:

    跑步:

    $ ssh -Tv git@github.com
    

    将显示您的 ./ssh/config 在此存储库中实际连接的身份。

    在这种情况下,它看起来像是在运行:

    debug1: /etc/ssh/ssh_config line 19: Applying options for *
    

    并使用您的默认用户名,即 TOTALLY_DIFFERENT_WRONG_USERNAME。

    您可以像这样创建不同的配置:

    # user1
    Host github.com
        HostName github.com
        User user1
    
    # user2
    Host github.com
        HostName github.com
        User user2
    

    【讨论】:

    • 事实证明这实际上不起作用,因此请接受实际答案。
    猜你喜欢
    • 1970-01-01
    • 2016-02-13
    • 2013-05-06
    • 2018-08-02
    • 1970-01-01
    • 2016-07-27
    • 2023-03-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多