GitでNot possible to fast-forward, aborting.エラーが出た時の対処法
2024.04.18
いつも忘れるのでメモ。
ローカルでコミットした後、リモートをプルするときすでにリモートに新しいコミットが作られているとFast forwardが失敗し表題のエラーが発生する。
以下のコマンドでローカルにリモートのコミットを取り込むといい。
git pull --rebase origin main
解説
自分はgit config --global pull.ff only
でFast forwardのみを許可しているので以下のような時しかRemote
からLocal
にpull
できない。
%%{init: { 'gitGraph': {'mainBranchName': 'Remote'}} }%%
gitGraph
commit id: "1"
commit id: "2" tag: "origin"
branch Local
checkout Local
commit id: "3"
commit id: "4" tag: "main"
以下のような時、
%%{init: { 'gitGraph': {'mainBranchName': 'Remote'}} }%%
gitGraph
commit id: "1"
commit id: "2"
branch Local
checkout Local
commit id: "3"
commit id: "4" tag: "main"
checkout Remote
commit id: "5" tag: "origin"
Fast forward onlyだとmerge
できない。
%%{init: { 'gitGraph': {'mainBranchName': 'Remote'}} }%%
gitGraph
commit id: "1"
commit id: "2"
branch Local
checkout Local
commit id: "3"
commit id: "4" tag: "main"
checkout Remote
commit id: "5" tag: "origin"
checkout Local
merge Remote type: REVERSE
rebase
する必要がある。
%%{init: { 'gitGraph': {'mainBranchName': 'Remote'}} }%%
gitGraph
commit id: "1"
commit id: "2"
commit id: "5" tag: "origin"
branch Local
checkout Local
commit id: "3"
commit id: "4" tag: "main"