はじめに
いつも通りgit pushしたらエラーが発生して実行できませんでした。
同じことが起きた人のメモになればと思い、対処法を書き残します。
起こったエラー
$ git push origin master
To https://github.com/my_app
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/my_app'
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.
原因
push予定のコミットをする前に、リモートのgithubを編集していたこと。
私はwebサイトで作成したER図を直接リモートgithubに追加していました。
解決
方法①
git pull origin develop
でリモート環境をpullした後、再度pushする。
方法②
git fetch
した後、mergeする。
方法③
git push --force
で強制的にpushする。
個人開発やチーム開発などによる状況によって使い分けるのがよさそうですね。