1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Git】git pushしたらrejectされた時のエラー解決方法!non-fast-forwardやgit configも対応!

Posted at

概要

  • 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.
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.
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.
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
  • まだまだ学ぶことが多い日々です!
1
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?