我试图按照迈克尔哈特尔的Rails教程,但我遇到了一个错误。
我在GitHub注册了,发放了一个新的SSH密钥,并创建了一个新的存储库。但是当我在终端中输入下一行时,我得到了以下错误:
Parkers-MacBook-Pro:.ssh ppreyer$ git remote add origin git@github.com:ppreyer/first_app.git
fatal: remote origin already exists.
只是想知道是否有人遇到过这个问题?
我试图按照迈克尔哈特尔的Rails教程,但我遇到了一个错误。
我在GitHub注册了,发放了一个新的SSH密钥,并创建了一个新的存储库。但是当我在终端中输入下一行时,我得到了以下错误:
Parkers-MacBook-Pro:.ssh ppreyer$ git remote add origin git@github.com:ppreyer/first_app.git
fatal: remote origin already exists.
只是想知道是否有人遇到过这个问题?
当前回答
如果你已经为另一个存储添加了项目,比如你上传到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 -v
将返回如下格式的列表:
origin git@github.com:github/git-reference.git (fetch)
origin git@github.com:github/git-reference.git (push)
这可能会帮助你弄清楚最初的“原点”指的是什么。
如果你想保留你用-v看到的远程连接,但仍然想遵循Rails教程,而不必记住'github'(或其他一些名称)用于教程的repo,你可以使用命令重命名你的其他存储库:
git remote rename [current name] [new name]
如:
git remote rename origin oldrepo
然后您应该能够继续您的教程。
在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 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
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
简而言之:
看看你已经有了什么, 删除或重命名它们, 添加您的新别名。
快乐的编码。