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

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

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

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


当前回答

我在远程推送代码时,在Bitbucket中面临问题

遵循以下步骤:

步骤1:更新现有的远程

git remote set-url origin https://pratik@bitbucket.org/pratik/demoapp.git

步骤2:您可以使用此命令强制使用本地存储库对服务器进行更改。远程回购代码将被本地回购代码取代。

git push -f origin master

-f通常,该命令拒绝更新不是用来覆盖它的本地引用的祖先的远程引用。

其他回答

要查看您有多少个别名以及它们是什么,您可以启动这个命令 Git remote -v

然后查看您在哪个存储库中 那就试试 git remote set-url——add[然后你的存储链接] Git push -u origin master

短版:

您只需更新现有的远程:

$ 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 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

如果你已经为另一个存储添加了项目,比如你上传到github,然后你上传到bitbucket,然后它会显示这种类型的错误。

如何删除错误:删除git-hub文件,然后重复以下步骤…

git init       
git remote add origin git@bitbucket.org:Yourname/firstdemotry.git  
git add -A  
git commit -m 'Message'  
git push -u origin master  

使用此命令更新已经存在的源

git remote set-url origin https://github.com/SriramUmapathy/ReduxLearning.git