提交第一个Git存储库时出现问题。

5

我是Git的新手,已经设置好并创建了我的第一个存储库。我试图将README作为第一次提交添加,我一直在按照http://help.github.com/create-a-repo/上的步骤进行操作,但是我在这一步卡住了:

git push -u origin master

我收到了这个错误信息:
ERROR: username/Hello-World.git doesn't exist. Did you enter it correctly?

我认为问题出在我错误地使用了git remote add命令:我忘记替换我的用户名和仓库名称。使用正确的参数重试后,命令如下:

$ git remote add origin git@github.com:christineh/Hello-World.git
 fatal: remote origin already exists.
$ git push -u origin master
Enter passphrase for key '/Users/christinehorvat/.ssh/id_rsa':
 ERROR: username/Hello-World.git doesn't exist. Did you enter it correctly?
 fatal: The remote end hung up unexpectedly'

我该如何清理这个并获取正确的遥控器?

你在 git remote add 命令中替换了你的用户名和 git 仓库名称,对吧? - Mat
你有 GitHub 账户吗?我按照http://help.github.com/create-a-repo/ 上的步骤在 GitHub 上创建了一个叫做 Hello-World 的仓库。GitHub 提示我在本地机器上使用的远程设置命令是 git remote add origin git@github.com:srivaths/Hello-World.git。请注意,其中没有"用户名"。 - Sri Sankaran
@Sri Sankaran - 当我输入以下命令时,这是我得到的结果: $ git remote add origin git@github.com:christineh/Hello-World.git 致命错误:远程源已经存在。 - Christine Horvat
@Mat 我试了一下,这是再次尝试时发生的情况:Christine-Horvats-MacBook-Pro-2:Hello-World christinehorvat$ git remote add origin git@github.com:christineh/Hello-World.git
fatal: 远程源已经存在。
Christine-Horvats-MacBook-Pro-2:Hello-World christinehorvat$ git push -u origin master
输入密钥'/Users/christinehorvat/.ssh/id_rsa'的密码:
错误:username/Hello-World.git不存在。您是否正确输入?
fatal: 远程端意外挂起。
- Christine Horvat
@ChristineHorvat:尝试使用 git remote rm origin 命令,然后重新启动 git remote add origin 命令,确保您准确地输入了您的 GitHub 用户名和仓库名称。 - Mat
1
即使您找到了解决自己问题的方法,或者有人在评论中发布了解决方案,您也应该将其作为“答案”发布并接受,而不是将其添加到您的问题中作为编辑。这样,它就不会一直出现在未回答的问题列表中。 - Duncan Babbage
1个回答

15
你只需要使用以下命令删除有错误引用的origin远程分支即可:
$ git remote rm origin

然后重新启动添加和推送,就应该可以了。

$ git remote add origin git@github.com:christineh/Hello-World.git
$ git push -u origin master

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接