如何切换到新的远程git存储库

时间:2016-09-06 14:31:24

标签: git github

我最近克隆了一个repo到我的本地驱动器,但现在我正在尝试将所有更改推送到一个完整的新回购。然而,git一直告诉我许可被拒绝,那是因为它试图推送到最初克隆的回购。

详情:

我最初是从https://github.com/taylonr/intro-to-protractor克隆的(即基于https://app.pluralsight.com/library/courses/protractor-introduction/table-of-contents的Pluralsight课程。)

现在我已经完成了课程,我想把我最终的代码推到我自己的git repo(我刚刚在github上创建):

https://github.com/robertmazzo/intro-to-protractor

当我使用以下git命令时:

  

git remote add origin https://github.com/robertmazzo/intro-to-protractor.git

它告诉我remote origin already exists,我猜这很好,因为我已经在github.com上创建了它。

但是,当我推动我的更改时,我会遇到异常。

  

git push origin master

remote: Permission to taylonr/intro-to-protractor.git denied to robertmazzo. fatal: unable to access 'https://github.com/taylonr/intro-to-protractor.git/': The requested URL returned error: 403

所以我正在研究如何切换到我的新存储库,但这正是我的问题所在。我无法弄明白这一部分。

4 个答案:

答案 0 :(得分:1)

origin 只是标识远程存储库的别名。

您可以创建新的远程引用并按

git remote add new_origin https://github.com/robertmazzo/intro-to-protractor.git
git push new_origin master

如果您想删除之前的

git remote remove origin

答案 1 :(得分:0)

添加新的遥控器

git remote add <name> <url>

或者,如果您想完全删除旧origin,请先执行

git remote remove origin

然后

git remote add origin <url>

请注意,消息remote origin already exists不正常。它告诉您操作失败,即它无法设置新的遥控器。

答案 2 :(得分:0)

在添加名为&#34; origin&#34;的新遥控器之前,您需要删除旧遥控器,或者只是因为某些原因仍需要访问它而只需重命名它。

# Pick one
git remote remove origin            # delete it, or ...
git remote rename origin old-origin # ... rename it

# Now you can add the new one
git remote add origin https://github.com/robertmazzo/intro-to-protractor.git

答案 3 :(得分:0)

要将当前原点更改为新的原点,请使用:

git remote set-url origin <url>

来源: https://help.github.com/articles/changing-a-remote-s-url/

相关问题