更改从本地机器上的github分支的项目的远程仓库(Rstudio) [英] change remote repo for a project forked from github on local machine (Rstudio)

查看:130
本文介绍了更改从本地机器上的github分支的项目的远程仓库(Rstudio)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

This question seems obvious, but I can't seem to find a direct answer in my searching of stackoverflow and other corners of the internet.

我有一个要在本地计算机上使用R Studio的项目.该项目是从Github上的一个仓库开始的.我不能推送到此仓库,因为它不是我的仓库,并且我没有允许.没什么大不了的,我想在github上创建一个新的存储库,以将所有更改保存到原始存储库和项目的当前状态.我不能只输入:

I have a project I work on using R studio on a local machine. The project started by pulling from a repo on Github. I can't push to this repo, as its not mine and I don't have permission. No big deal, I'd like to create a new repository on github to save all my changes to the original repo and the current state of the project. I can't just enter:

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

因为已经有一个遥远的起源.我收到此错误:

Because there is already a remote origin. I receive this error:

fatal: remote origin already exists.

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

Right. This is clear. The origin is the original github repository that I pulled this from, and also the one I am not allowed to update because its not my code. Straightforward. I want to change the origin of the repository to: https://github.com/user/new_repo.git (the new repo I just setup on github), but save all of the work history of how I have modified the project.

很抱歉,如果这是重复的,并且我不理解对类似问题的其他回答.

Apologies if this is a duplicate and I don't understand the other responses to similar questions.

推荐答案

我使用@manishrw的建议以及其他几篇文章解决了这个问题.我需要做几件事:

I solved this problem using advice from @manishrw, and several other posts. I needed to do several things:

首先 我需要在.git/config文件中更改原始远程URL.这可以由@manishrw详细说明,并且实际的URL文件路径需要为ssh://git@github.com/user/new_repo.git.因此,在主目录中,您将输入:

First, I needed to change the origin remote url in the .git/config file. This could be accomplished as detailed by @manishrw, and the actual URL filepath needed to be ssh://git@github.com/user/new_repo.git. So, from the home directory you would enter:

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

到目前为止,一切都很好.但是,我仍然遇到问题,因为我正在从未认证的远程计算机上工作.我会收到错误:

So far so good. However, I still had problems, as I was working from a remote computer which had never been authenticated. I would get the error:

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

第二,要解决此问题,我必须在远程计算机上为github设置用户名和电子邮件,然后生成SSH密钥.我按照此处的说明进行了总结.下方:

Second, To solve this I had to setup my username and email for github on the remote machine, and then generate an SSH key. I followed instructions here, which I summarize below:

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

  1. Set username and email at the shell within R studio. These are your github.com username and email.

git config --global user.name您的用户名" git config --global user.email"your_email@example.com"

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

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

In RStudio, go to menu Tools / Global options / Git SVN

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

Click "Create RSA key..." and follow instructions. You can set a password here, but its not necessary.

单击查看公用密钥"并复制密钥.

Click "view public key" and copy the key.

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

Copy the key to your Github account setting (Edit profile / SSH keys / Add SSH key).

要检查ssh身份验证是否有效,请尝试运行

To check that ssh-authentication works, try to run

ssh -T git@github.com

您应该得到类似的东西

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

现在一切都应该很棒.

Everything should now work awesome.

这篇关于更改从本地机器上的github分支的项目的远程仓库(Rstudio)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆