【问题标题】:git push is pushing to the wrong repogit push 推送到错误的仓库
【发布时间】:2015-11-05 18:20:18
【问题描述】:

最近在网上学习了一门编程课程,要求我们将家庭作业上传到 Github,从那时起,每当我输入 git push -u origin master 时,我都会收到:

remote: Permission to my-github-username/mygithubrepo.git denied to rheros.
fatal: unable to access 'https://github.com/my-github-username/mygithubrepo.git/': The requested URL returned error: 403

rheros 是我用来推送家庭作业的存储库的名称。显然,现在我不再使用rheros,但命令行认为我仍在尝试推送它。我尝试检查我是否有错误的 SSH 密钥,但一切看起来都很好。

如何让我的命令行有效地忘记我之前推送到的完全不相关目录的存在?

编辑 git remote --verbose 给:

origin  https://github.com/my-github-username/mygithubrepo.git (fetch)
origin  https://github.com/my-github-username/mygithubrepo.git (push)

到目前为止,以下建议都没有帮助我:rheros repo 似乎在我的命令行后台某处运行,我不知道如何消除它。

【问题讨论】:

  • 您能否添加(并评论)git remote --verbose 的结果
  • @user3276552 完成,请参阅编辑。
  • @user3276552 看来 rheros 正在尝试访问我的 .git....如何删除此活动?
  • 而不是 git remote add origin github.com/my-github-username/mygithubrepo.git,应该是 git remote set-url origin github.com/USERNAME/OTHERREPOSITORY.git 来改变原点
  • @MaxPinto 是的,但我不是rheros。我想重置自己,这样我的电脑就不会认为我作为rheros 正在尝试访问https://github.com/my-github-username/mygithubrepo.git

标签: github


【解决方案1】:

git remote add origin https://github.com/my-github-username/mygithubrepo.git

然后再次尝试推送

【讨论】:

    【解决方案2】:

    首先检查当前的 git 存储库是什么,如果有的话:

    git remote -v
    

    然后,通过检查 github 网站并复制正确的存储库 url 来确认您的新存储库存在

    通过运行覆盖存储库 url:

    git remote add origin https://github.com/my-github-username/mygithubrepo.git
    

    再次尝试 git push:

    git push origin master
    

    【讨论】:

    • 使用set-url而不是add如果你得到“致命:远程来源已经存在”
    【解决方案3】:

    查看此处讨论的解决方案:https://superuser.com/questions/1064197/how-to-switch-git-user-at-terminal

    我的问题是 git 凭据存储在钥匙串中。从钥匙串中删除它们,你可能会有一些运气。

    【讨论】:

      【解决方案4】:
      git remote remove origin https://github.com/my-github-username/mygithubrepo.git
      

      之后,你就可以正常添加你想要推送的仓库了

      【讨论】:

        【解决方案5】:

        如果您想更改当前的原始路径,请尝试:

        git remote set-url origin https://github.com/USERNAME/REPOSITORY.git
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2013-03-28
          • 1970-01-01
          • 1970-01-01
          • 2013-03-07
          • 1970-01-01
          • 2019-07-29
          相关资源
          最近更新 更多