【问题标题】:change remote repo for a project forked from github on local machine (Rstudio)在本地机器(Rstudio)上更改从 github 分叉的项目的远程仓库
【发布时间】:2015-12-11 15:09:37
【问题描述】:

这个问题似乎很明显,但我在搜索 stackoverflow 和互联网的其他角落时似乎找不到直接答案。

我有一个项目,我正在本地机器上使用 R studio。该项目从 Github 上的一个 repo 开始。我不能推送到这个 repo,因为它不是我的而且我没有权限。没什么大不了的,我想在 github 上创建一个新的存储库来保存我对原始存储库的所有更改和项目的当前状态。我不能只输入:

git remote add origin https://github.com/user/new_repo.git

因为已经有一个远程源。我收到此错误:

fatal: remote origin already exists.

没错。这很清楚。来源是我从中提取的原始 github 存储库,也是我不允许更新的存储库,因为它不是我的代码。直截了当。我想将存储库的来源更改为:https://github.com/user/new_repo.git(我刚刚在 github 上设置的新存储库),但保存我如何修改项目的所有工作历史。

抱歉,如果这是重复的,我不明白其他类似问题的回答。

【问题讨论】:

    标签: git github rstudio


    【解决方案1】:

    应该这样做。

    git remote set-url origin newurl
    

    编辑

    当您使用 git 只读地址进行克隆时(主要是在您不登录时),那么您将无法获得读写访问权限。

    Repository 需要改变它使用 ssh 推送的方式。按照此answer 将您 PC 上的 repo 配置更改为 ssh 方式。

    【讨论】:

    • 我这样做了,但是当我去推送时,我得到了这个错误:error: The requested URL returned error: 403 Forbidden while accessing https://github.com/user/new_repo.git/info/refs
    • 如果你能改变问题,恰当地描述问题,这对其他人也有帮助!
    • 我按照另一篇文章中的说明对配置文件进行了更改。我现在去推送时收到此错误:Permission denied (publickey). fatal: The remote end hung up unexpectedly
    【解决方案2】:

    我使用@manishrw 的建议和其他几篇帖子解决了这个问题。我需要做几件事:

    首先, 我需要更改 .git/config 文件中的原始远程 url。这可以通过@manishrw 详细说明来完成,并且实际的 URL 文件路径需要是ssh://git@github.com/user/new_repo.git。因此,您可以从主目录输入:

    git remote set-url origin ssh://git@github.com/user/new_repo.git
    

    到目前为止一切顺利。但是,我仍然遇到问题,因为我是在从未经过身份验证的远程计算机上工作。我会得到错误:

    Permission denied (publickey). fatal: The remote end hung up unexpectedly
    

    第二,为了解决这个问题,我必须在远程机器上为 github 设置我的用户名和电子邮件,然后生成一个 SSH 密钥。我遵循了here 的说明,我总结如下:

    1. 在 R studio 的 shell 中设置用户名和电子邮件。这些是您的 github.com 用户名和电子邮件。

      git config --global user.name "your_username" git config --global user.email "your_email@example.com"

    2. 在 RStudio 中,转到菜单工具/全局选项/Git SVN

    3. 单击“创建 RSA 密钥...”并按照说明进行操作。您可以在此处设置密码,但这不是必需的。

    4. 单击“查看公钥”并复制密钥。

    5. 将密钥复制到您的 Github 帐户设置(编辑配置文件/SSH 密钥/添加 SSH 密钥)。

    要检查 ssh-authentication 是否有效,请尝试运行

    ssh -T git@github.com
    

    你应该得到类似的东西

    Hi your_username! You’ve successfully authenticated, but GitHub does not provide shell access. 
    

    现在一切都应该很棒。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-11
      • 1970-01-01
      • 2021-11-17
      • 2018-06-25
      • 2012-07-03
      • 2021-11-02
      相关资源
      最近更新 更多