【问题标题】:Gitlab: How to git pull without credentials?Gitlab:如何在没有凭据的情况下进行 git pull?
【发布时间】:2022-10-21 13:45:09
【问题描述】:

我在我的服务器上生成了一个id_ed25519 密钥并将其设置在Gitlab 中,当我尝试使用SSH 连接时,我收到了欢迎消息,但是当使用git pull 时,它仍然需要凭据(用户名和密码)。

$ ssh -T git@gitlab.com
Welcome to GitLab, @john.doe!
$ git pull
Username for 'https://gitlab.com': john.doe
Password for 'https://john.doe@gitlab.com': 
Already up to date.

我的配置中缺少什么?

【问题讨论】:

    标签: gitlab


    【解决方案1】:

    我想这可能是因为您使用的是 https git remote url 而不是 ssh 。

    【讨论】:

    • 就是这样,谢谢!所以我在.git/config段落[remote "origin"]中用url = git@gitlab.com:john.doe/myproject.git替换了url = https://gitlab.com/john.doe/myproject.git,它起作用了。
    【解决方案2】:

    请检查您配置的遥控器,它应该是 https 的:

    $ git remote -v
    origin https://gitlab.com/john.doe/myproject.git (fetch)
    origin https://gitlab.com/john.doe/myproject.git (push)
    

    您需要将其更改为 SSH 之一:

    $ git remote set-url origin git@gitlab.com:john.doe/myproject.git
    

    这完成了 OP 在已接受答案的评论中提到的内容,而无需手动编辑配置文件。请也赞成接受的答案:)

    【讨论】:

      猜你喜欢
      • 2020-03-22
      • 2021-11-06
      • 2022-01-15
      • 2021-03-01
      • 2016-10-01
      • 2014-03-04
      • 2020-03-05
      • 1970-01-01
      相关资源
      最近更新 更多