我试图按照迈克尔哈特尔的Rails教程,但我遇到了一个错误。

我在GitHub注册了,发放了一个新的SSH密钥,并创建了一个新的存储库。但是当我在终端中输入下一行时,我得到了以下错误:

Parkers-MacBook-Pro:.ssh ppreyer$ git remote add origin git@github.com:ppreyer/first_app.git
fatal: remote origin already exists.

只是想知道是否有人遇到过这个问题?


当前回答

$ git remote add origin git@gitlab.com:abc/backend/abc.git In this command origin is not part of command it is just name of your remote repository. You can use any name you want. First You can check that what it contains using below command $ git remote -v It will gives you result like this origin git@gitlab.com:abc/backend/abc.git (fetch) origin git@gitlab.com:abc/backend/abc.git (push) origin1 git@gitlab.com:abc/backend/abc.git (fetch) origin1 git@gitlab.com:abc/backend/abc.git (push) if it contains your remote repository path then you can directly push to that without adding origin again If it is not contaning your remote repository path Then you can add new origin with different name and use that to push like $ git remote add origin101 git@gitlab.com:abc/backend/abc.git Or you can rename existing origin name add your origin git remote rename origin destination fire below command again $ git remote -v destination git@gitlab.com:abc/backend/abc.git (fetch) destination git@gitlab.com:abc/backend/abc.git (push) It will change your existing repos name so you can use that origin name Or you can just remove your existing origin and add your origin git remote rm destination

其他回答

短版:

您只需更新现有的远程:

$ git remote set-url origin git@github.com:ppreyer/first_app.git

长版:

正如错误消息所示,已经有一个配置了相同名称的远程服务器。因此,您可以使用不同的名称添加新的远程设备,如果不需要的话,也可以更新现有的远程设备。

要添加一个新的远程,例如,调用github而不是origin(显然已经存在于您的系统中),执行以下操作:

$ git remote add github git@github.com:ppreyer/first_app.git

记住,尽管在教程中你看到“起源”,你应该把它换成“github”。例如$ git push origin master现在应该是$ git push github master。

但是,如果你想查看已经存在的原始远程是什么,你可以执行$ git remote -v。如果你认为这是由于一些错误,你可以这样更新它:

$ git remote set-url origin git@github.com:ppreyer/first_app.git

为了使用git,你必须

如果没有,那就用sudo

去除原点: Git远程删除原点

添加原点:

Git远程添加origin http://giturl

$ git remote add origin git@gitlab.com:abc/backend/abc.git In this command origin is not part of command it is just name of your remote repository. You can use any name you want. First You can check that what it contains using below command $ git remote -v It will gives you result like this origin git@gitlab.com:abc/backend/abc.git (fetch) origin git@gitlab.com:abc/backend/abc.git (push) origin1 git@gitlab.com:abc/backend/abc.git (fetch) origin1 git@gitlab.com:abc/backend/abc.git (push) if it contains your remote repository path then you can directly push to that without adding origin again If it is not contaning your remote repository path Then you can add new origin with different name and use that to push like $ git remote add origin101 git@gitlab.com:abc/backend/abc.git Or you can rename existing origin name add your origin git remote rename origin destination fire below command again $ git remote -v destination git@gitlab.com:abc/backend/abc.git (fetch) destination git@gitlab.com:abc/backend/abc.git (push) It will change your existing repos name so you can use that origin name Or you can just remove your existing origin and add your origin git remote rm destination

请将“git remote add origin git@github.com”中的“add”替换为“git remote set-url origin git@github.com”中的“set-url

试试这个命令,对我有用。

Rm -rf .git/