---
name: git-rebase-helper
description: "A safe, step-by-step rebase plan for your branch: the exact commands in order, what the interactive editor should look like, how to resolve each conflict, and how to abort or recover if it goes wrong. Use when a branch needs rebasing onto main, commits need squashing or reordering, or a rebase is stuck in conflicts and the user wants the exact commands. Do not use for choosing between merge and rebase as a team policy, or recovering commits that have already been garbage collected. Related topics: coding, workflow, git."
---

# Git Rebase Helper

A safe, step-by-step rebase plan for your branch: the exact commands in order, what the interactive editor should look like, how to resolve each conflict, and how to abort or recover if it goes wrong.

## When to use

Use this skill when a branch needs rebasing onto main, commits need squashing or reordering, or a rebase is stuck in conflicts and the user wants the exact commands. Do not use it for choosing between merge and rebase as a team policy, or recovering commits that have already been garbage collected.

## Workflow

1. Ask the user for each input listed below in a single message, skipping any they have already given. Where options are listed, offer them, but accept other answers too.
2. Create a safety net first: a backup branch or tag at the current tip and a fetch of the target, so the rebase can be undone.
3. Lay out the rebase commands in execution order with the expected output after each, starting from the user's current state when they are mid-rebase.
4. Show the interactive todo list with each line marked pick, squash, fixup, or reword and the reason, when interactive is on.
5. Explain conflict resolution per file: read the markers, resolve, git add, continue, and the point at which aborting and merging is the better choice.
6. End with the correct push command for the branch's sharing state and the coordination note when others already have the old history.

## Inputs

- **Branch being rebased** (free text, e.g. "feature/login-form")
- **Target branch to rebase onto** (free text, e.g. "main")
- **Number of commits on my branch** (number from 1 to 50)
- **Interactive rebase to squash or reorder** (choose one: Yes, No)
- **Is the branch already pushed and shared** (choose one: Not pushed, Pushed but only I use it, Pushed and others have it)
- **Current problem (if any)** (longer free text)

## Output

A numbered command walkthrough with the expected state after each step, an interactive todo list where relevant, a conflict-resolution routine, and the final push command with its safety caveat.

## Prompt template

Fill the inputs into this template and follow it as the full instruction.

### Git Rebase Helper

Walk me through rebasing my branch safely.

#### The branch
- Branch being rebased: {{Branch being rebased}}
- Target branch to rebase onto: {{Target branch to rebase onto}}
- Number of commits on my branch: {{Number of commits on my branch}}
- Interactive rebase to squash or reorder: {{Interactive rebase to squash or reorder}}
- Is the branch already pushed and shared: {{Is the branch already pushed and shared}}
- Current problem (if any): {{Current problem (if any)}}

Start with a safety net: a backup branch or tag at the current tip, and a fetch so the target is current, before anything rewrites history. Give the commands in the exact order to run them, one per line, with the expected output or editor view after each. For an interactive rebase, show the todo list as it will appear and mark which lines become squash, fixup, or reword and why. For conflicts, explain how to read the markers, resolve one file at a time, git add it, and continue, and when to prefer git rebase --abort and a merge instead. Finish with the push: force-with-lease for a branch only the user has, and a warning plus coordination steps for a branch others have pulled. If the user is already mid-rebase, start from their current state instead of the beginning.

## Pitfalls

- Rebasing a branch that teammates have already pulled without warning them, which leaves everyone with duplicate commits.
- Suggesting git push --force instead of --force-with-lease, which silently overwrites work pushed by someone else.
- Skipping the backup ref, so a bad squash cannot be undone without digging through reflog.
