为什么Git提交到错误的存储库?
我在Michael Hartl的Ruby on Rails教程的第2章中,在命令行中键入了以下内容:为什么Git提交到错误的存储库?,git,github,Git,Github,我在Michael Hartl的Ruby on Rails教程的第2章中,在命令行中键入了以下内容: $ git init $ git add . $ git commit -m "Initial commit" $ git remote add github https://github.com/themaktravels/demo_app.git fatal: remote github already exists. $ git push -u github master Use
$ git init
$ git add .
$ git commit -m "Initial commit"
$ git remote add github https://github.com/themaktravels/demo_app.git
fatal: remote github already exists.
$ git push -u github master
Username:
Password:
To https://github.com/themaktravels/first_app.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/themaktravels/first_app.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again. See the
'Note about fast-forwards' section of 'git push --help' for details.
在注意到Github存在之前,我看到了一个致命错误,但我认为这没关系,因为我之前在另一个存储库中提交了Git。我注意到,当我$git push-u Github master
时,结果是git试图在错误的存储库(first_app.git)而不是新创建的存储库(demo_app.git)中提交。为什么会这样
在尝试提交之前,我输入了以下内容:
$ cd ~/rails_projects
$ rails new demo_app
$ cd demo_app
然后编辑了我的gem文件,一切看起来都很好。直到我遇到这个git问题。有什么建议吗?多谢各位
为防止丢失历史记录,拒绝了非快进更新
在再次按下之前,合并远程更改(例如“git pull”)
就像它试图告诉你的一样,推送试图导致非快进更新。问题在于这里的这一点:
$ git remote add github https://github.com/themaktravels/demo_app.git
fatal: remote github already exists.
如果您已经有一个名为
github
的远程设备,那么git remote add
命令将不会更改现有设置。使用git remote-v
查看您当前的遥控器及其指向的位置。我怀疑您已经有一个名为github
的遥控器指向https://github.com/themaktravels/first_app.git
您已经有一个名为“github”的遥控器,它指向第一个应用程序,因此当您尝试添加新的遥控器时,它指向演示应用程序,但失败
看起来您试图在一个已经存在并且已经有远程服务器的存储库中初始化Git。确保在新目录中执行此操作 我刚刚试过,
$git remote-v
,看起来我还有一个用于演示的github\u app.git。。。以下是输出:githubgit@github.com:themaktravels/demo_app.git(fetch)
githubgit@github.com:makTravels/demo_app.git(推送)
原点git@github.com:(提取)
原点git@github.com:(按)
。这是否意味着在创建新回购协议之前,我必须将“github”重命名为其他名称?