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

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

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

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


当前回答

试试这个

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

其他回答

对于那些遇到非常常见的错误“fatal: remote origin already exists.”,或者当试图删除origin时得到“error: could not remove config section remote.”原点”,你需要做的就是手动设置原点。

Windows的POSH~Git for Windows PowerShell(和GitHub for Windows的应用程序)在这方面有一个问题。

就像我经常遇到的那样,我又一次在布置我的章鱼女时遇到了这种情况。这就是我如何让它工作的。

首先,检查你的遥控器:

C:\gd\code\octopress [source +2 ~3 -0 !]> git remote -v
octopress       https://github.com/imathis/octopress.git (fetch)
octopress       https://github.com/imathis/octopress.git (push)
origin

您首先会注意到我的原点没有url。任何删除它、重命名它的尝试都失败了。

因此,手动更改url:

git remote set-url --add origin https://github.com/eduncan911/eduncan911.github.io.git

然后你可以再次运行git remote -v来确认它是有效的:

C:\gd\code\octopress [source +2 ~3 -0 !]> git remote -v
octopress       https://github.com/imathis/octopress.git (fetch)
octopress       https://github.com/imathis/octopress.git (push)
origin  https://github.com/eduncan911/eduncan911.github.io.git (fetch)
origin  https://github.com/eduncan911/eduncan911.github.io.git (push)

这已经修复了数十个我遇到的问题,GitHub, BitBucket GitLab等。

$ 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 push -u origin main

如果你想通过GUI做以下事情:

确保“隐藏文件”在项目文件夹中可见 进入“。git”目录 编辑config.txt文件中的url文件并保存该文件!

这工作:

git remote rm origin
git remote add origin git@github.com:username/myapp.git