Skip to content

Instantly share code, notes, and snippets.

@Aurora12
Last active October 16, 2025 16:12
Show Gist options
  • Select an option

  • Save Aurora12/4a171640308f347124b64b51a3f73c9b to your computer and use it in GitHub Desktop.

Select an option

Save Aurora12/4a171640308f347124b64b51a3f73c9b to your computer and use it in GitHub Desktop.
Rebase your Git branch on top of target accepting all changes from your branch, including file deletions and renamings.

Solution

A way to solve this in a non-interactive way:

# Optional but helpful: remember conflict resolutions
git config rerere.enabled true
git config rerere.autoupdate true
git config rerere.autoreuse true

# don't auto-open editor on merges
export GIT_MERGE_AUTOEDIT=no

# make any commit/editor step a no-op
export GIT_EDITOR=:

# Start the rebase resolving all *content* conflicts in favour of the feature branch.
if ! git rebase -X theirs <TARGET BRANCH>; then

  # Rebase stopped on a conflict; loop until done
  while true; do
    # Keep the feature-commit side for all conflicted paths
    git checkout --theirs .
    git add -A

    # Continue; returns 0 when the entire rebase finishes,
    # non-zero when it hits the next conflict
    if git rebase --continue; then
      break
    fi
  done
fi

# Push your rebase
git push

Explanation

You can accept all content changes from your branch. Which, during a rebase, is "theirs" — not "ours".

git checkout <TARGET BRANCH>
git pull
git checkout <YOUR FEATURE BRANCH>
git rebase -X theirs <TARGET BRANCH>

The problem is, the deletions and renamings are not processed automatically, as they are not content conflicts. So you do need to do the following manual steps a number of times every time the rebase stops with a message like "CONFLICT (modify/delete): <...> deleted in HEAD and modified in <...>. Version <...> of <...> left in tree.":

git checkout --theirs .
git add -A
git rebase --continue
:wq

To avoid this manual work, use the solution from above.

Note: Consider doing this on a throwaway branch first: git branch backup/FEATURE_BRANCH && git checkout -b tmp/autorebase.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment