【问题标题】:Troubleshooting git push - it asks for a user/passgit push 疑难解答 - 它要求用户/通行证
【发布时间】:2011-04-28 04:46:29
【问题描述】:

我在一台新的 git linux 计算机上使用 git。当我执行git push 时,我会询问用户/密码。

我已经正确设置了 git,实际上将 repo 从 github 克隆到一个新文件夹中效果很好(使用我的公钥,而不是只读副本)。当我尝试从以前的克隆推送到同一个仓库时,系统会提示我输入用户/通行证。

当然 sshing 进入 git@github.com 是可行的,而且我确保我的公钥已在 github 中配置。任何想法如何继续调试?

【问题讨论】:

    标签: git github


    【解决方案1】:

    这是因为你这样做了

    git clone https://github.com/username/repo
    

    而不是

    git clone git@github.com:username/repo.git
    

    【讨论】:

    • 有时这不是一个选择!
    【解决方案2】:

    尝试以下方法:

    git remote set-url origin [你的git url,如git@github.com:.../project.git]

    【讨论】:

    • 运行此命令后,我得到“输入密钥'/u/.ssh/id_rsa'的密码:”我知道密码,但是有没有办法让它停止基于密钥文件到位了吗?
    • 为避免在每次推送时输入您的密钥密码,请尝试 ssh-add。您需要运行 ssh-agent 才能将密钥添加到 SSH 代理。 A simple man page here
    • 你是真正给出解决方案的人,而不是仅仅说出问题所在!
    • 我这样做了,但它仍然要求输入用户名。可能仅适用于某些 URL。
    【解决方案3】:

    以前的回购是什么意思?从上一个 repo 的 .git/config 文件中检查来源的 url。如果您使用 http 进行克隆,它会询问用户/密码。

    【讨论】:

    • 你是对的,问题是 HTTP URL。 “以前的回购”是指同一回购的以前克隆。
    【解决方案4】:

    如果你的 repo Url 是:https://github.com/abc/xyz.git

    从命令行设置 url 为:git remote set-url origin git@github.com:abc/xyz.git

    https://github.com/ 替换为git@github.com:

    【讨论】:

    • 但如果 repo 不支持 ssh proto 则不支持
    【解决方案5】:

    根据我的经验,有三种情况

    1. git remote set-url github(remote repo name) https://github.com/id/a.git
        it asks ID/Passwd
    2. git remote set-url github https://id@github.com/id/a.git
        it only asks Passwd
    3. git remote set-url github git://github.com:id/a.git
        if you don't have a permission, it complains. So I can't use this for public server of github
    

    所有命令都写入“.git/config”

    【讨论】:

    • 修复了我的 HTTPS 缺少 @github.com 之前的用户名
    【解决方案6】:

    for mac 如果你有 git 1.7.10+ 它需要使用 credential-osxkeychain 来缓存密码。这是一个很好的解释:

    https://help.github.com/articles/set-up-git

    【讨论】:

      【解决方案7】:

      也许这会对像我这样的人有所帮助。

      缓存密码的方法请看Git官方文章

      链接:https://help.github.com/en/articles/caching-your-github-password-in-git

      命令:

      1. 设置 Git 使用凭证内存缓存

        > git config --global credential.helper cache

      2. 更改默认缓存超时

        > git config --global credential.helper 'cache --timeout=3600'

      【讨论】:

      • 这会缓存用户名和密码,但是当缓存过期时仍然需要输入。
      猜你喜欢
      • 2012-11-16
      • 1970-01-01
      • 2013-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多