Gitのrebase-merge directoryエラーの直し方
git rebase が「It seems that there is already a rebase-merge directory」で止まるのは、前に始めた rebase の記録(.git/rebase-merge)が残っているためです。git status で途中の rebase を確かめ、git rebase --continue で最後まで進めるか、git rebase --abort でやめると、記録が消えて次の rebase が動きます。
競合で止まった rebase のことを忘れたまま、ブランチを main に追従させようとして git rebase main や git pull --rebase を実行したときに出るエラーです。
検証環境は Ubuntu 24.04、Git 2.43.0、bash 5.2 です。英語のメッセージにそろえるため LANG=C で実行しました。rebase の進み具合の表示(Rebasing (1/2) など)は、出力から省いて載せています。Windows・macOS、VS Code などのエディターに組み込まれた Git の画面、git rebase --apply などで使われる rebase-apply のほうの記録は試していません。
出たエラーメッセージ
検証環境で、競合で止まった rebase をそのままにして、もう一度 git rebase main を実行すると、次のメッセージが出て、終了コード 128 で止まりました。
$ git rebase main
fatal: It seems that there is already a rebase-merge directory, and
I wonder if you are in the middle of another rebase. If that is the
case, please try
git rebase (--continue | --abort | --skip)
If that is not the case, please
rm -fr ".git/rebase-merge"
and run me again. I am stopping in case you still have something
valuable there.
日本語にすると「rebase-merge のフォルダーがすでにあるようです。別の rebase の途中ではありませんか。そうなら git rebase (--continue | --abort | --skip) を試してください。そうでないなら rm -fr ".git/rebase-merge" でフォルダーを消してから、もう一度 git rebase を実行してください。大事なものが残っているかもしれないので、ここで止めます」という意味です。
rebase-merge フォルダーが残っている状態で git pull --rebase . main と git rebase -i main を実行しても、一字一句同じメッセージで止まりました(このときは、空のフォルダーを作って試しています)。git pull --rebase のほうは、取得(From . の行)までは進み、そのあとの rebase で止まります。
.git/rebase-merge は、途中の rebase の記録
.git/rebase-merge は、rebase が途中で止まっている間、どこまで進んだか、残りに何をするかを置いておくフォルダーです。競合で止まったときの中身は、次のとおりでした。
$ ls .git/rebase-merge
author-script
done
drop_redundant_commits
end
git-rebase-todo
git-rebase-todo.backup
head-name
interactive
message
msgnum
no-reschedule-failed-exec
onto
orig-head
patch
stopped-sha
ファイルの中を見ると、head-name には元のブランチの名前(refs/heads/feature)、onto には付け替え先の main のコミット、git-rebase-todo にはまだ当てていないコミットの一覧が入っていました。
Git は、このフォルダーがあるだけで「rebase の途中」と判断し、新しい rebase を始めようとすると、上のメッセージを出して止まります(Git 2.43.0 のソースコードで判断している箇所と、メッセージを出している箇所)。Git は、head-name などのファイルがそろっているかまでは見ません。検証環境でも、空の rebase-merge フォルダーを作っただけで同じメッセージが出ました。
最初に git status で、途中の rebase を確かめる
メッセージは rm -fr も案内していますが、先に git status を見ます。競合で止まっている場合は、次のように表示されました。
$ git status
interactive rebase in progress; onto bb94d1f
Last command done (1 command done):
pick d7b5337 featureでメモを変更
Next command to do (1 remaining command):
pick 33f3fbc todoを追加
(use "git rebase --edit-todo" to view and edit)
You are currently rebasing branch 'feature' on 'bb94d1f'.
(fix conflicts and then run "git rebase --continue")
(use "git rebase --skip" to skip this patch)
(use "git rebase --abort" to check out the original branch)
Unmerged paths:
(use "git restore --staged <file>..." to unstage)
(use "git add <file>..." to mark resolution)
both modified: memo.txt
no changes added to commit (use "git add" and/or "git commit -a")
feature ブランチを bb94d1f の上に付け替える途中で、1つ目のコミットを当てたところ、memo.txt が競合して止まっている、という意味です。この続きをするかやめるかで、使うコマンドが変わります。

続けるなら、競合を直して –continue
止まっている rebase を最後まで進めたいときは、競合したファイルを直して git add し、git rebase --continue を実行します。git rebase の公式リファレンスによると、--continue は、競合を解決したあとに rebase を再開するオプションです。
検証環境では、memo.txt を直して git add し、git rebase --continue を実行すると、残りのコミットも当たって rebase が終わりました(コミットメッセージを書くエディターは開かないようにしています)。
$ git add memo.txt
$ GIT_EDITOR=true git rebase --continue
[detached HEAD 78d106a] featureでメモを変更
1 file changed, 1 insertion(+)
Successfully rebased and updated refs/heads/feature.
$ ls .git | grep rebase
$ git rebase main
Current branch feature is up to date.
ls .git | grep rebase が何も表示しないので、rebase-merge は消えています。もう一度 git rebase main を実行すると、エラーではなく「Current branch feature is up to date.」(すでに最新)と表示されました。
やめるなら –abort で、始める前のブランチに戻す
前の rebase がもう要らないときは、git rebase --abort を実行します。公式リファレンスによると、--abort は、rebase をやめて HEAD を元のブランチに戻すオプションです。
$ git rebase --abort
$ ls .git | grep rebase
$ git status --short --branch
## feature
$ git log --oneline
33f3fbc todoを追加
d7b5337 featureでメモを変更
02e635b 最初のコミット
rebase-merge が消え、feature ブランチは rebase を始める前のコミットに戻りました。このあと git rebase main を実行すると、エラーにはならず、rebase が最初からやり直されました(この例では同じ場所でもう一度競合しました)。
todo リストの編集中に Git が止まったときも –abort で戻る
git rebase -i の todo リストをエディターで開いている間に、Git のプロセスが kill -9 で強制終了された状態も作りました。pgrep -a git は何も表示せず、動いている Git はありません。それでも rebase-merge は残り、次の git rebase main は同じメッセージで止まりました。
このときの git status は、次のように表示されました。まだ何も当てていないのに「You are currently editing a commit」と出ますが、ブランチは feature のままで、コミットも動いていません。
$ git status
On branch feature
No commands done.
Next commands to do (2 remaining commands):
pick d7b5337 featureでメモを変更
pick 33f3fbc todoを追加
(use "git rebase --edit-todo" to view and edit)
You are currently editing a commit while rebasing branch 'feature' on '554fc51'.
(use "git commit --amend" to amend the current commit)
(use "git rebase --continue" once you are satisfied with your changes)
nothing to commit, working tree clean
この状態でも git rebase --abort は成功し、rebase-merge が消えました。続けて git rebase main を実行すると、エラーにならずに最後まで進みました。
$ git rebase --abort
$ git rebase main
Successfully rebased and updated refs/heads/feature.
head-name がなく –abort が失敗するときは –quit
rebase-merge に head-name がないと、--abort が失敗します。検証環境では、中身が空の rebase-merge フォルダーを作って試しました。git rebase --abort は、元のブランチの名前を記録した head-name が読めないという warning を出して終了コード 1 で終わり、フォルダーは残ったままでした。
$ git rebase --abort
warning: could not read '.git/rebase-merge/head-name': No such file or directory
$ ls .git | grep rebase
rebase-merge
このときは git rebase --quit を使います。公式リファレンスによると、--quit は、rebase をやめるものの、HEAD を元のブランチに戻さず、インデックスと作業ツリーもそのままにするオプションです。検証環境でも、--quit で rebase-merge が消え、次の git rebase main が最後まで進みました。メッセージが案内している rm -fr ".git/rebase-merge" でフォルダーを消した場合も、同じように次の rebase が動きました。
$ git rebase --quit
$ ls .git | grep rebase
$ git rebase main
Successfully rebased and updated refs/heads/feature.
--quit と rm -fr は、途中の rebase の記録を消すだけで、ブランチを元に戻しません。競合で止まっている rebase に使ったところ、どちらでも HEAD は付け替え先の main のコミット(bb94d1f)のままブランチから切り離され(HEAD detached from refs/heads/feature)、memo.txt は競合したままでした。途中の rebase の記録が壊れていないなら、--continue か --abort で片付けてください。
rm -fr のあとに git rebase main を実行すると、今度は「error: cannot rebase: You have unstaged changes.」という別のエラーで止まりました。どちらの場合も、feature ブランチ自体は rebase を始める前のコミット(33f3fbc)のままでした。競合した作業ツリーの変更を git reset --hard で捨ててから git switch feature を実行すると、元のブランチに戻れました。git reset --hard は作業ツリーの変更を消すので、残したい変更がないかを先に確かめてください。
git worktree で作った作業フォルダーでは、rebase-merge の場所が違う
git worktree add で作った作業フォルダーで同じエラーが出たときは、メッセージの rm -fr に出るパスが .git/rebase-merge ではありませんでした(リポジトリのパスは /path/to/repo に置き換えています)。
$ git rebase feature
fatal: It seems that there is already a rebase-merge directory, and
I wonder if you are in the middle of another rebase. If that is the
case, please try
git rebase (--continue | --abort | --skip)
If that is not the case, please
rm -fr "/path/to/repo/.git/worktrees/wt/rebase-merge"
and run me again. I am stopping in case you still have something
valuable there.
git worktree の公式リファレンスの DETAILS の節にあるとおり、worktree で作った作業フォルダーには、それぞれ元のリポジトリの .git/worktrees/ の下に専用のフォルダーがあります。rebase の記録もそこに置かれていました。場所は、その作業フォルダーの中で git rev-parse の --git-path を使って確かめられます。
$ git rev-parse --git-path rebase-merge
/path/to/repo/.git/worktrees/wt/rebase-merge
元のリポジトリで同じコマンドを実行すると、.git/rebase-merge と表示されました。worktree の作業フォルダーでも git rebase --abort で同じように片付けられます。検証環境では、.git/worktrees/wt/rebase-merge が消え、その作業フォルダーのブランチ(topic)に戻りました。





