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

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

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

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


当前回答

在Windows上使用git bash将存储库添加到git hun时遇到同样的错误

 git remote add origin https://github.com/axaysushir/netflix_page_clone.git

致命:远程源已经存在。

fatal: remote origin already exists.

 ! [rejected]        master -> master (fetch first)

错误:无法将一些引用推到“https://github.com/axaysushir/meditation_app_using_js.git”

通过以下命令更新存储库

$ git remote set-url origin https://github.com/axaysushir/netflix_page_clone.git

然后添加存储库使用git远程添加github而不是git远程添加起源

$ git remote add github https://github.com/axaysushir/netflix_page_clone.git

然后写以下命令,而不是git push origin master,这将把你的存储库上传到github

$ git push github master

其他回答

$ 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

如果你需要检查你已经连接到本地回购的远程回购,有一个cmd:

git remote -v

现在,如果你想删除远程回购(比如,origin),那么你可以做的是:

git remote rm origin

如果在没有初始化git的情况下在directory中运行命令,也会发生这种情况。如果是这种情况,首先运行:

git init

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

简而言之:

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

快乐的编码。

如果你已经为另一个存储添加了项目,比如你上传到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