質問: bitbucketでローカルのリポジトリをリモートのoriginにpushしてrejectされました。 git pullしてpushすれば良いとあったので実行しましたが、うまくできません。 以下にコマンドのメッセージを添付します。 どのように解決すればよいのかご教示ください。 $ git push -u origin --all Warning: Permanently added the RSA host key for IP address '18.205.93.1' to the list of known hosts. To bitbucket.org:goma_leyley/hello_app.git ! [rejected] master -> master (fetch first) Branch modify-README set up to track remote branch modify-README from origin. error: failed to push some refs to 'git@bitbucket.org:●●●●/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. ここでpullしました $ git pull origin master remote: Counting objects: 9, done . remote: Compressing objects: 100% (6/6), done. remote: Total 9 (delta 2), reused 0 (delta 0) Unpacking objects: 100% (9/9), done. From bitbucket.org:g●●●●/hello_app * branch master -> FETCH_HEAD * [new branch] master -> origin/master Auto packing the repository in background for optimum performance. See "git help gc" for manual housekeeping. fatal: refusing to merge unrelated histories $ git push -u origin --all To bitbucket.org:●●●●/hello_app.git ! [rejected] master -> master (non-fast-forward) Branch modify-README set up to track remote branch modify-README from origin. error: failed to push some refs to 'git@bitbucket.org:goma_leyley/hello_app.git' hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Integrate the remote changes (e.g. hint: 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details. 宜しくお願いします。
回答: git pullしたの時のメッセージを良く見ましょう。 > > fatal: refusing to merge unrelated histories > > > ということで、マージに失敗しているようです。 "fatal: refusing to merge unrelated histories"で検索すると、いろんなサイトが引っかかります。 https://stackoverflow.com/questions/37937984/git-refusing-to-merge-unrelated-histories-on-rebase https://qiita.com/takanatsu/items/fc89de9bd11148da1438 https://hacknote.jp/archives/31307/ これらを参考に、 ``` git merge --allow-unrelated-histories origin/master ``` を実行してみるとどうでしょうか。