我试图按照迈克尔哈特尔的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 remove origin

然后使用你的命令

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

如果您不想删除现有的远程记录,请更新它

git remote set-url <REMOTE-NAME> <NEW-URL>

然后使用你的命令

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

如果要重命名现有项目,请使用以下命令

git remote rename <old-name> <new-name>

如果要将原始远程重命名为backup。你只需运行:

git remote rename origin backup

谢谢你! !

其他回答

$ 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

remote的概念就是远程存储库的URL。

原点是指向该URL的别名。因此,我们不需要在每次想要将东西推送到存储库时都写入整个URL,只需使用这个别名并运行:

Git push -u origin master

告诉git将我们的代码从本地主分支推到远程源存储库。

每当我们克隆一个存储库时,git默认为我们创建这个别名。此外,每当我们创建一个新的存储库时,我们只是自己创建它。

不管它是什么情况,我们总是可以把这个名字改为任何我们喜欢的,运行这个:

git remote rename [current-name] [new-name]

由于它存储在git应用程序的客户端(在我们的机器上),更改它不会影响我们的开发过程,也不会影响我们的远程存储库。记住,它只是一个指向地址的名称。

这里通过重命名别名所做的唯一更改是,每次将内容推入存储库时都必须声明这个新名称。

Git push -u my-remote-alias master

显然,一个名字不能指向两个不同的地址。这就是为什么您会得到这个错误消息。在本地机器上已经有一个名为origin的别名。要查看你有多少个别名,它们是什么,你可以启动这个命令:

git remote -v

这将显示您拥有的所有别名以及相应的url。

你也可以删除它们,如果你喜欢运行这个:

git remote rm my-remote-alias

简而言之:

看看你已经有了什么, 删除或重命名它们, 添加您的新别名。

快乐的编码。

在特殊情况下,您正在从用作模板的旧存储库开始创建新的存储库(如果不是您的情况,请不要这样做)。完全擦除旧存储库的git文件,这样你就可以开始一个新的存储库:

rm -rf .git

然后像往常一样重新启动一个新的git存储库:

git init
git add whatever.wvr ("git add --all" if you want to add all files)
git commit -m "first commit"
git remote add origin git@github.com:ppreyer/first_app.git
git push -u origin master

该错误消息表明您的git目录中已经有一个远程服务器。 如果您对那个遥控器感到满意,您就可以推送您的代码。如果没有或者你不能推,就:

git remote remove origin
git remote add origin git@github.com:ppreyer/first_app.git

瞧!

试试这个

cd existing_repo Git远程重命名原点old-origin