如何切换到新的远程 Git 仓库

23
我最近将一个repo克隆到本地驱动器,但现在我想将所有更改推送到一个全新的repo。然而,git一直告诉我权限被拒绝,因为它试图推送到最初克隆的repo。
细节:
我最初从https://github.com/taylonr/intro-to-protractor(即基于Pluralsight课程https://app.pluralsight.com/library/courses/protractor-introduction/table-of-contents)进行了克隆。
现在,我完成了课程,想将我的最终代码推送到我自己的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 所以我正在调查如何切换到我的新存储库,但这正是我的问题所在。我无法解决这个部分。

1
可能是更改远程Git仓库的URI(URL)的重复问题。 - Julien Lopez
4个回答

24

14

在添加一个名为“origin”的新远程之前,您需要删除旧的远程,或者如果您因某些原因仍需要访问它,则将其重命名。

# 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

8

origin只是用来标识你的远程仓库的别名。

你可以创建一个新的远程引用并进行推送。

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

如果您想删除之前的引用
git remote remove origin

2

添加一个新的远程仓库

git remote add <name> <url>

或者,如果你想完全删除旧的 origin,请先执行以下操作:

git remote remove origin

然后

git remote add origin <url>

请注意,消息“remote origin already exists”并不好。它告诉您该操作失败,即无法设置新的远程。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接