【问题标题】:Git asks password for wrong username whenever I git pull or push每当我 git pull 或 push 时,Git 都会询问错误用户名的密码
【发布时间】:2021-01-27 04:00:06
【问题描述】:

我有一个 repo - 假设它的远程地址是 https://myself@bitbucket.org/myself/my-repo.git。我正在与我的同事共享此存储库 - 我已授予他对他帐户的此存储库的管理员访问权限。假设他的 bitbucket 帐户是 https://mycolleague@bitbucket.org。他克隆了 repo。但是,每当他尝试推送/拉取存储库时,git 都会询问我的帐户 (https://myself@bitbucket.org) 而不是他的帐户 (https://mycolleague@bitbucket.org) 的密码。如何更改 git 设置,以便 git 询问他的帐户 (https://mycolleague@bitbucket.org) 而不是我的?

提前致谢!

【问题讨论】:

  • 您的同事克隆了 https://myself@bitbucket.org/myself/my-repo.git 而不是 https://mycolleague@bitbucket.org/myself/my-repo.git。修复它的方法是让您的同事编辑.git/config 文件,找到引用repo 的[remote] 条目并修复URL。应该不需要重新获取 repo。

标签: git github bitbucket


【解决方案1】:

首先,您可以通过键入查看用于 BitBucket 存储库的 URL

git remote -v

这很可能表明您克隆的同事有一个指定您的用户名的遥控器。解决此问题的最简单方法是从 url 中删除用户名:

git remote set-url origin https://bitbucket.org/myself/my-repo.git

现在当他们 push/pull/fetch/etc 时,git 会询问用户名和 url。

如果您的同事不想每次都输入用户名,那么他们可以改为这样做

git remote set-url origin https://colleague@bitbucket.org/myself/my-repo.git

如果您对总是输入用户名和密码感到恼火,我建议您设置一个 SSH 密钥并将公钥上传到 BitBucket。 BitBucket 文档解释了如何做到这一点。 SSH 非常方便,可以安全地访问您的帐户。

【讨论】:

    【解决方案2】:

    他需要使用 URL https://mycolleague@bitbucket.org/myself/my-repo.git 来克隆 repo——注意它的用户名在一个地方,而你的用户名在另一个地方。

    【讨论】:

      猜你喜欢
      • 2021-04-07
      • 2012-06-13
      • 1970-01-01
      • 2012-07-09
      • 2018-02-06
      • 2018-02-05
      • 2014-03-09
      • 2022-01-25
      • 2014-05-03
      相关资源
      最近更新 更多