端くれプログラマの備忘録 Git [Git] non-fast-forward updates were rejected 対処法

[Git] non-fast-forward updates were rejected 対処法

ローカルのリポジトリをプッシュしようとしたらエラー。

$ git push origin mybranch
To https://xxxx@bitbucket.org/xxxx/myrepo.git
! [rejected] mybranch -> mybranch (non-fast-forward)
error: failed to push some refs to 'https://xxxx@bitbucket.org/xxxx/myrepo.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes before pushing again. See the 'Note about
fast-forwards' section of 'git push --help' for details.

プッシュする前にリモートリの変更をマージしろと言われたので以下で対処。

$ git fetch
$ git merge origin/mybranch
Merge made by recursive.
...