概要
- git pushしたら以下エラーと遭遇したので、その対応方法を記しておく。
! [rejected] ...error: failed to push some refs to...
Updates were rejected because the remote contains work that you do...
! [rejected] ...(non-fast-forward)
You have divergent branches and need to specify how to reconcile them
エラー内容
- いつものように
git add .
とgit commit
を実施してからgit push origin xxx
したら、以下エラーメッセージが返された。
To xxxxxxxxx.git
! [rejected] feature/1 -> feature/1 (fetch first)
error: failed to push some refs to 'xxxxxxxxx.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.
-
rejectじゃと?!
-
「前回と今回の push までの間にリモートが更新されているので、あなたのローカルに存在しないファイルがある」という意味らしいので、リモートファイルの取得とマージを行なってみよう
-
git fetch
を実施
remote: Enumerating objects: 353, done.
remote: Counting objects: 100% (353/353), done.
remote: Compressing objects: 100% (128/128), done.
remote: Total 353 (delta 190), reused 316 (delta 166), pack-reused 0
Receiving objects: 100% (353/353), 103.22 KiB | 308.00 KiB/s, done.
Resolving deltas: 100% (190/190), completed with 11 local objects.
From xxxxxx...
-
git merge
を実施
fatal: No remote for the current branch.
-
あれ、、だめだ、リモートにないと言われてる
-
git push
を実施してみると、
fatal: The current branch feature/1 has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin feature/1
To have this happen automatically for branches without a tracking
upstream, see 'push.autoSetupRemote' in 'git help config'.
- 上記のようにかえってきたので、
git push --set-upstream origin feature/1
を実施
To xxxxxxxxx.git
! [rejected] feature/1 -> feature/1 (non-fast-forward)
error: failed to push some refs to 'xxxxxxxxx.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.
- (non-fast-forward)という、微妙に違うエラーになった。下記を参考に
git pull origin feature/1
を実施
From xxxxxxxxx
* branch feature/1 -> FETCH_HEAD
hint: You have divergent branches and need to specify how to reconcile them.
hint: You can do so by running one of the following commands sometime before
hint: your next pull:
hint:
hint: git config pull.rebase false # merge
hint: git config pull.rebase true # rebase
hint: git config pull.ff only # fast-forward only
hint:
hint: You can replace "git config" with "git config --global" to set a default
hint: preference for all repositories. You can also pass --rebase, --no-rebase,
hint: or --ff-only on the command line to override the configured default per
hint: invocation.
fatal: Need to specify how to reconcile divergent branches.
-
今度はまた別のエラーだ(^^;)
-
git pull時に、分岐したブランチに対する設定を促す警告らしい。
- 3つのうちいずれかやっておきなさい、とのことなので、
git config pull.rebase false
をまずは実施 - 参考記事:Gitの警告"You have divergent branches and need to specify how to reconcile them."は、pull時分岐したブランチに対する設定を明確にすることで解決する。
- 3つのうちいずれかやっておきなさい、とのことなので、
-
git pull origin feature/1
を実施すると、pullできたぞ!
From xxxxxxxxx
* branch feature/1 -> FETCH_HEAD
Merge made by the 'ort' strategy.
#####
#省略
-
git push origin feature/1
を行うと、無事にpush完了!よしゃあー!!!!
Enumerating objects: 38, done.
Counting objects: 100% (33/33), done.
Delta compression using up to 10 threads
Compressing objects: 100% (24/24), done.
Writing objects: 100% (26/26), 6.85 KiB | 3.43 MiB/s, done.
Total 26 (delta 11), reused 5 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (11/11), completed with 4 local objects.
To xxxxxxxxx.git
01988a0..2568093 feature/1 -> feature/1
- まだまだ学ぶことが多い日々です!