LoginSignup
2
0

More than 5 years have passed since last update.

git push (Ruby on Railsチュートリアル5章の5.5で発生)

Posted at

はじめに

Ruby on Railsチュートリアル5章の最後のgit push実施時に発生したエラーとそれを解決するときに行った方法をまとめました。

エラーログ

ec2-user:~/environment/sample_app (master) $ git push
Username for 'https://github.com': xxx@example.com
Password for 'https://xxx@example.com@github.com': 
To https://github.com/xxx/xxx.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/xxx/xxx.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

ec2-user:~/environment/sample_app (master) $ git status
On branch master
Your branch and 'origin/master' have diverged,
and have 1 and 2 different commits each, respectively.
  (use "git pull" to merge the remote branch into yours)

'origin/master = originという名前のレポジトリのmasterブランチ'

origin/masterからリモートとローカルでコミット差分があった際に発生する場合にこういった状態になるみたいです。

②git pull

Already up-to-date!
Merge made by the 'recursive' strategy.

とりあえず'recursive' strategyでマージされたみたいです。

③git fetch

ログ出力無し

④git merge origin/master

Already up-to-date!

特に問題なさそうです。

⑤git push

Username for 'https://github.com': xxx@example.com
Password for 'https://xxx@example.com@github.com': 
Counting objects: 42, done.
Compressing objects: 100% (40/40), done.
Writing objects: 100% (42/42), 155.97 KiB | 13.00 MiB/s, done.
Total 42 (delta 15), reused 0 (delta 0)
remote: Resolving deltas: 100% (15/15), completed with 14 local objects.
remote: This repository moved. Please use the new location:
remote:   https://github.com/xxx/xxx.git
To https://github.com/xxx/xxx.git
   xxx..xxx  master -> master

無事pushできました。

参考資料

◆エラーログ出力前(git pushする前)のgit log


commit xxx..xxx (HEAD -> master, filling-in-layout)
Author: xxx <xxx@example.com>
Date:   Sat Feb 2 07:59:59 2019 +0000

    Finish layout and routes

commit xxx..xxx
Author: xxx <xxx@example.com>
Date:   Mon Jan 28 12:55:15 2019 +0000

    Add a full_title helper

◆手順④実施後のgit log


commit xxx..xxx (HEAD -> master)
Merge: xxx xxx
Author: xxx <xxx@example.com>
Date:   Sat Feb 2 08:07:23 2019 +0000

    Merge branch 'master' of https://github.com/xxx/xxx

commit xxx..xxx (filling-in-layout)
Author: xxx <xxx@example.com>
Date:   Sat Feb 2 07:59:59 2019 +0000

    Finish layout and routes

commit xxx (origin/master)
Merge: xxx xxx
Author: xxx <xxx@example.com>
Date:   Sat Feb 2 06:54:40 2019 +0000

    Merge branch 'master' of https://github.com/xxx/xxx

commit xxx
Author: xxx <xxx@example.com>
Date:   Mon Jan 28 12:55:15 2019 +0000

    Add a full_title helper

参考サイト

gitで「Your branch and 'origin/***' have diverged」と言われたときの対処
【GIT】git pushしたら、error: failed to push some refs toとでたときの原因と対処法

2
0
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
2
0