質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Git

Gitはオープンソースの分散バージョン管理システム(DVCS)です。

GitHub

GitHubは、Gitバージョン管理システムを利用したソフトウェア開発向けの共有ウェブサービスです。GitHub商用プランおよびオープンソースプロジェクト向けの無料アカウントを提供しています。

Q&A

解決済

2回答

3988閲覧

github masterでpushしようとすると怒られる。

purogram001

総合スコア17

Git

Gitはオープンソースの分散バージョン管理システム(DVCS)です。

GitHub

GitHubは、Gitバージョン管理システムを利用したソフトウェア開発向けの共有ウェブサービスです。GitHub商用プランおよびオープンソースプロジェクト向けの無料アカウントを提供しています。

0グッド

0クリップ

投稿2019/06/03 08:32

前提・実現したいこと

ポートフォリオを更新しようと思っています。
https://berukokoko.github.io/beru/
githubでプッシュしようと思ったところ、エラーが発生して進めません。
サイトを更新したいのですが、どうすればプッシュできるのでしょうか?

発生している問題・エラーメッセージ

ターミナルで下記のコマンドを打ったところ、下記のエラーが発生しています。

$ git push origin master
To https://github.com/berukokoko/beru.git ! [rejected] master -> master (non-fast-forward) error: failed to push some refs to 'https://github.com/berukokoko/beru.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 add . $ git mommit -m "インデックス更新"

②プッシュしました。

$ git push origin master To https://github.com/berukokoko/beru.git ! [rejected] master -> master (non-fast-forward) error: failed to push some refs to 'https://github.com/berukokoko/beru.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 origin masterをしました。
下記サイトを参考に、pullしました。
https://qiita.com/katsuyuki/items/8e03e5eb4223912a08c5

$ git pull origin master From https://github.com/berukokoko/beru * branch master -> FETCH_HEAD * [new branch] master -> origin/master fatal: refusing to merge unrelated histories

④git merge --allow-unrelated-histories origin/masterをしました。
refusing to merge unrelated historiesが出たため、下記をを参考に
git merge --allow-unrelated-histories origin/masterコマンドを打ちました。
https://qiita.com/takanatsu/items/fc89de9bd11148da1438

$ git merge --allow-unrelated-histories origin/master Auto-merging js/controller.js CONFLICT (add/add): Merge conflict in js/controller.js Auto-merging index.html CONFLICT (add/add): Merge conflict in index.html Auto-merging image/torin.jpg CONFLICT (add/add): Merge conflict in image/torin.jpg Auto-merging css/a.css CONFLICT (add/add): Merge conflict in css/a.css Automatic merge failed; fix conflicts and then commit the result.

⑤git pull origin masterをしました。

$ git pull origin master error: You have not concluded your merge (MERGE_HEAD exists). hint: Please, commit your changes before merging. fatal: Exiting because of unfinished merge.

⑥git push origin masterを再びしてみたところ、変わらなかったです。

$ git push origin master To https://github.com/berukokoko/beru.git ! [rejected] master -> master (non-fast-forward) error: failed to push some refs to 'https://github.com/berukokoko/beru.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 statusで確認したところ下のようになっています。

$ git status On branch master You have unmerged paths. (fix conflicts and run "git commit") (use "git merge --abort" to abort the merge) Unmerged paths: (use "git add <file>..." to mark resolution) both added: css/a.css both added: image/torin.jpg both added: index.html both added: js/controller.js

参考にしました。
https://qiita.com/kyoyyy/items/161b6905f45bee2efe21

・git branch で確認したところ * masterになっています。

・gitについてよくわかっていないことだらけなのでご教授願います。
・mergeというのをしなければならないのでしょうか?
・masterとはブランチの名前であることは理解しました。
・originがレポジトリの名前の別名だとは理解しました。

プッシュできない理由に何が考えられますでしょうか?

補足情報(FW/ツールのバージョンなど)

macOS

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答2

0

ベストアンサー

まず、コンフリクト(ファイル変更の衝突)が発生しているということを認識しましょう。
コンフリクトとは、自分の修正内容と他人の修正内容が同じファイルの似たような箇所に発生していることを指していて、自動的にマージできないことを意味しています。
(他人、と書きましたが別のタイミングの自分自身かもしれません)

You have unmerged paths. (fix conflicts and run "git commit") (use "git merge --abort" to abort the merge) Unmerged paths: (use "git add <file>..." to mark resolution) both added: css/a.css both added: image/torin.jpg both added: index.html both added: js/controller.js

この4つのファイルがマージできなかったファイルです。
ちゃんと手順もメッセージの中に書いてあって、

  • fix conflicts and run "git commit" : コンフリクトを修正し、 git commit を実行してください
  • use "git merge --abort" to abort the merge : マージを中止するには git merge --abort を使ってください

とあります。
コンフリクトの修正とは、自分と他人の修正内容を組み合わせて、正しいファイルの状態にすることです。
試しに css/a.css の内容を確認してもらえるとわかると思うのですが、

<<<<<<< HEAD (自分で書いた修正内容) ======= (他人が書いた修正内容) >>>>>>> master

という箇所があると思います。これを変更して「正しい」状態にしてください。どんな状態が正しいのかはあなた自身が判断するしかありません。
修正が終わったら、 git add で修正が終わった状態であることを記録します。
4ファイルすべて修正が完了したら、 git commit でマージした内容をコミットしてください。
その後、 git push できるはずです。

投稿2019/06/04 01:43

mather

総合スコア6753

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

purogram001

2019/06/04 08:55

ありがとうございます。コンフリクトについて知らなかったので、調べて確認してみます。
guest

0

私もgit初心者(というかほぼ使ってない)なので、合っているかわかりませんが...
④で自動マージに失敗しているので、手動で競合を解消する必要があります。
https://qiita.com/nfnoface/items/8823bfb8f50c4c90412d
ここを参考にしてみてください。

投稿2019/06/03 10:21

ozraru

総合スコア150

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

purogram001

2019/06/04 08:55

ありがとうございます。確認してみます。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問