Ruby on Railsチュートリアル始めました。
早速1章でつまづいたところがあったので、まとめてみます。
問題(エラー内容)
1章のGitのところのBitbucketへのpushでエラーが起きました。
あれ、pushできない?
手順通りにやったはずなのに。
少し焦りました。
[text]
rails_user:~/environment/hello_app (master) $ git push -u origin –all
To bitbucket.org:rails_user/hello_app.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to ‘git@bitbucket.org:rails_user/hello_app.git’
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., ‘git pull …’) before pushing again.
hint: See the ‘Note about fast-forwards’ in ‘git push –help’ for details.
[/text]
原因
リポジトリを見てみると「README.md」が存在することに気づきました。
これが原因で整合性が取れなくて、pushできなくなっているようです。
ちなみに「README.md」の有無は、リポジトリ作成時「READMEを含めますか?」で設定できます。
デフォルトは「YES」になっているので、作成時は「NO」にしておきましょう。

解決策
一番簡単な方法は、強制Pushして上書きする方法かと思います。
[text]git push -f origin master[/text]
他には、リモートリポジトリの「README.md」の削除することで解決できます。
所感
デフォルトで作成される「README.md」が原因とは、盲点でした。
1時間近くハマってしまったので、今後は同じエラーではまらないようにしたいです。