github masterでpushしようとすると怒られる。
解決済
回答 2
投稿
- 評価
- クリップ 0
- VIEW 1,910
前提・実現したいこと
ポートフォリオを更新しようと思っています。
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
-
気になる質問をクリップする
クリップした質問は、後からいつでもマイページで確認できます。
またクリップした質問に回答があった際、通知やメールを受け取ることができます。
クリップを取り消します
-
良い質問の評価を上げる
以下のような質問は評価を上げましょう
- 質問内容が明確
- 自分も答えを知りたい
- 質問者以外のユーザにも役立つ
評価が高い質問は、TOPページの「注目」タブのフィードに表示されやすくなります。
質問の評価を上げたことを取り消します
-
評価を下げられる数の上限に達しました
評価を下げることができません
- 1日5回まで評価を下げられます
- 1日に1ユーザに対して2回まで評価を下げられます
質問の評価を下げる
teratailでは下記のような質問を「具体的に困っていることがない質問」、「サイトポリシーに違反する質問」と定義し、推奨していません。
- プログラミングに関係のない質問
- やってほしいことだけを記載した丸投げの質問
- 問題・課題が含まれていない質問
- 意図的に内容が抹消された質問
- 過去に投稿した質問と同じ内容の質問
- 広告と受け取られるような投稿
評価が下がると、TOPページの「アクティブ」「注目」タブのフィードに表示されにくくなります。
質問の評価を下げたことを取り消します
この機能は開放されていません
評価を下げる条件を満たしてません
質問の評価を下げる機能の利用条件
この機能を利用するためには、以下の事項を行う必要があります。
- 質問回答など一定の行動
-
メールアドレスの認証
メールアドレスの認証
-
質問評価に関するヘルプページの閲覧
質問評価に関するヘルプページの閲覧
checkベストアンサー
+1
まず、コンフリクト(ファイル変更の衝突)が発生しているということを認識しましょう。
コンフリクトとは、自分の修正内容と他人の修正内容が同じファイルの似たような箇所に発生していることを指していて、自動的にマージできないことを意味しています。
(他人、と書きましたが別のタイミングの自分自身かもしれません)
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
できるはずです。
投稿
-
回答の評価を上げる
以下のような回答は評価を上げましょう
- 正しい回答
- わかりやすい回答
- ためになる回答
評価が高い回答ほどページの上位に表示されます。
-
回答の評価を下げる
下記のような回答は推奨されていません。
- 間違っている回答
- 質問の回答になっていない投稿
- スパムや攻撃的な表現を用いた投稿
評価を下げる際はその理由を明確に伝え、適切な回答に修正してもらいましょう。
0
私もgit初心者(というかほぼ使ってない)なので、合っているかわかりませんが...
④で自動マージに失敗しているので、手動で競合を解消する必要があります。
https://qiita.com/nfnoface/items/8823bfb8f50c4c90412d
ここを参考にしてみてください。
投稿
-
回答の評価を上げる
以下のような回答は評価を上げましょう
- 正しい回答
- わかりやすい回答
- ためになる回答
評価が高い回答ほどページの上位に表示されます。
-
回答の評価を下げる
下記のような回答は推奨されていません。
- 間違っている回答
- 質問の回答になっていない投稿
- スパムや攻撃的な表現を用いた投稿
評価を下げる際はその理由を明確に伝え、適切な回答に修正してもらいましょう。
15分調べてもわからないことは、teratailで質問しよう!
- ただいまの回答率 88.19%
- 質問をまとめることで、思考を整理して素早く解決
- テンプレート機能で、簡単に質問をまとめられる
2019/06/04 10:44
こちらも参考にしてくださいね。
2019/06/04 17:55