git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[Feature request] allow git rebase while already rebasing

From
IGIsaac Oscar Gariano <isaacoscar@live.com.au>
Date
Aug 18, 2025, 19:29 UTC
Message-ID
<SYBP282MB29631756F18E53B16F2550848C31A@SYBP282MB2963.AUSP282.PROD.OUTLOOK.COM>

I've been doing a lot of interactive rebases lately, and I often edit a commit, continue to the next step of the rebase, and then realise theres' a change a forgot to make. Now usually, when I forget to do something in a commit, I do "git rebase -ir <bad-commit>", and then change the first "pick" line to "edit". Make changes, then "git add -u && git rebase --continue". Unfortunately, if I'm already in the process of a rebase it doesn't work: you can't have nested rebases.

I suggest removing this limitation, basically the idea is that if you do "git rebase" while you are already rebasing, it performs the following:
* it computes a new todo list as normal, and then prepends it to the current todo list
* it does a 'git reset --hard <start point>' like normal
Obviously there needs to be some limitations (e.g. it will probably only work on the merge backend).

If anyone knows of any tools that let you do this, it would be great. If people think it's likely to be accepted, I may make the changes to git myself to do this, but otherwise it's less work for me to just write a wrapper shell script with the features I actually might use.

In particular, the rest of this email is a fish script which demonstrates that one can actually do this:
	# This will likely not work properly in many cases, it's just a proof of concept
	if test (count $argv) -lt 1
		echo "USAGE: double-rebase <upstream> [<branch> [<new base> <rebase options>...]]"
                echo "which is like \"git rebase <upstream> <branch> --onto <new base> --interactive <rebase options>\"."
                echo "but for when you are already in a rebase"
		exit 1; end
	# Same defaults as git rebase
	if not set -q argv[2]
		set argv[2] HEAD; end
	if not set -q argv[3]
		set argv[3] $argv[1]; end
	set MAIN (git rev-parse --git-path rebase-merge)
	if not test -e $MAIN
		echo "fatal: rebase --merge not in progress"
		exit 1; end
	# Make a backup of the current rebase
	set BACKUP (git rev-parse --git-path rebase-backup)
	if test -e $BACKUP
		echo "fatal: $BACKUP already exists (did a previouse double-rebase crash?)"; end
	mv $MAIN $BACKUP || exit
	# This 'GIT_SEQUENCE_EDITOR' command will print the file to stdout, with 
	# lines starting with a # striped, and then blank the file.
	# Because the file gets blanked, git rebase won't actually do anything
	# to the repo.
	GIT_SEQUENCE_EDITOR="f () { rg -v '^#' \"\$@\"; echo > \"\$@\"; }; f" \
		git rebase -i $argv[4..] --onto=$argv[2] -- $argv[1] $argv[2] > $BACKUP/double-rebase-todo 2>$BACKUP/double-rebase-err
	mv $BACKUP $MAIN || exit
	# If the above rebase print anything to stderr other than an error about the file, being empty, something when wrong
	set -l stat $status
	if not diff -q $MAIN/double-rebase-err (echo "error: nothing to do" | psub)>/dev/null
		cat $MAIN/double-rebase-err >&2
		exit $stat
	end
	# Stupid hack to make the new labels unique
	set new_labels (rg '^\s*(l|label)\s+([^ \t#]+)' -or '$2' $MAIN/double-rebase-todo)
	set old_labels (rg "^\s*(l|label)\s+([^ \t#]+)" -or '$2' $MAIN/git-rebase-todo)
	set fresh_labels $new_labels
	# One of the new_labels is already in use, make a new version
	while string match -qr '^('(string join '|' -- $old_labels)')$' -- $fresh_labels
		set I (math $I + 1)
		set fresh_labels $new_labels$I
	end
	# Change to the new labels
	if test $I -gt 0
		rg '^\s*(l|label|t|reset)\s+([^ \t#]+)' -r '$1 ${2}'$I $MAIN/double-rebase-todo | sponge  $MAIN/double-rebase-todo
	end
	# Go to the <new base>
	git reset --hard $argv[3] || exit
	# Prepend the new todo list to the existing one
	cat $MAIN/double-rebase-todo $MAIN/git-rebase-todo | sponge $MAIN/git-rebase-todo || exit
	# Bassically act like git rebase -i would, except use the todo list we just constructed
	git rebase --edit-todo && git checkout $argv[2] && git rebase --continue
— Isaac Oscar Gariano​
Next: Oswald Buddenhagen
Message 1 of 3 in “[Feature request] allow git rebase while already rebasing”
  1. Isaac Oscar GarianoAug 18, 2025
  2. Oswald BuddenhagenAug 18, 2025
  3. Isaac Oscar GarianoAug 18, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.