LoginSignup
4
1

More than 5 years have passed since last update.

git pushするとエラー(railsチュートリアル)

Posted at

! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'http://(サーバーのリポジトリURL)'
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.

・原因
ローカルリポジトリが最新でないことが原因みたいです。

https://www.ipentec.com/document/git-error-non-fast-forward-in-git-pushによると
git reset コマンドなどを実行した後で、リモートリポジトリでは管理対象になっており、ローカルリポジトリでは管理対象外であり、ファイルが存在している場合、上記のエラーが発生します。管理対象外になったファイルをローカルのディレクトリから削除します。
という事も考えれるみたい。 

・解決法
まずgit fetchでもエラーが返ってくる。
git pull = git fetch → git merge
だからすべてダメかと思ったがhttps://qiita.com/takanatsu/items/fc89de9bd11148da1438によると
Git 2.9から mergeコマンドとpullコマンドでは,--allow-unrelated-historiesを指定しない限り,無関係なヒストリを持つ2つのブランチをマージすることはできなくなった。
とのことでgit merge --allow-unrelated-histories origin/master
をすると今までの
workspace/sample_app (master) $

workspace/sample_app (master|MERGING) $
に変わった。

よく見ると
$ git merge --allow-unrelated-histories origin/master
Auto-merging README.md
CONFLICT (add/add): Merge conflict in README.md
Automatic merge failed; fix conflicts and then commit the result.

と、conflictが発生している。ここはドットインストールのGIT入門を参考にvimで直した。

さて、改めてgit push origin master
結果は

Warning: Permanently added 'bitbucket.org,104.192.143.3' (RSA) to the list of known hosts.
Counting objects: 20, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (19/19), done.
Writing objects: 100% (20/20), 2.06 KiB | 1.03 MiB/s, done.
Total 20 (delta 14), reused 0 (delta 0)
To bitbucket.org:k-kiku/sample_app.git
fbf7b46..3397615 master -> master

4
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1