いつものようにgithubにpushしようとした時のこと下のエラーが出ました。
$ git push origin master
To github.com:hoeghoge/hugahgua
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:hogehoge/hugahuga'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and 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.
このエラーにはよく出会っていたのでさっさとpullしてpushしようとしました。
$ git pull origin master
From github.com:hogehoge/hugahuga
* branch master -> FETCH_HEAD
fatal: refusing to merge unrelated histories
???
よくわからないが、mergeできないぞって怒られた。
とりあえず、エラーをググるとヒストリーが繋がってないことを指摘されていたようだ。(そういえば、github側でsample.mdを作成していたので多分それですね)
オプション付けてpullすれば問題ないようなのでオプション付けてpullする。
$ git pull origin master --allow-unrelated-histories
From github.com:hogehoge/hugahuga
* branch master -> FETCH_HEAD
Merge made by the 'recursive' strategy.
README.md | 1 +
1 file changed, 1 insertion(+)
create mode 100644 README.md
お、mergeできた。
あとはお約束のadd〜pushの流れを実行
$ git add .
$ git commit -m "forst_commit"
On branch master
nothing to commit, working tree clean
$ git push origin master
Enumerating objects: 6, done.
Counting objects: 100% (6/6), done.
Delta compression using up to 4 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (5/5), 29.64 KiB | 7.41 MiB/s, done.
Total 5 (delta 0), reused 0 (delta 0)
To github.com:hogehoge/hugahuga
66edb0e..18fc410 master -> master
無事pushできました。