Skip to content
Back to skills

Rebase Branch

ASecurity

Rebases a branch onto another branch and resolves each conflict. Use when rebasing onto a mainline, continuing a rebase that is already in progress, resolving rebase conflicts, or when a pull request conflicts with its base branch.

  • 3 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added November 13, 2026
ai-agentsgobashgit

Security analysis

A100/100

Pro scans all 2 files and shows the line behind each finding

Scanned December 6, 2026

npx -y skills add mazzsva/claude-skills --skill rebase-branch --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Rebase Branch?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Rebase Branch
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/mazzsva-rebase-branch/badge)](https://www.skillsdirectory.com/skills/mazzsva-rebase-branch)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: rebase-branch
description: Rebases a branch onto another branch and resolves each conflict. Use when rebasing onto a mainline, continuing a rebase that is already in progress, resolving rebase conflicts, or when a pull request conflicts with its base branch.
---

# Rebase Branch

## Goal

Move a branch onto the newest commits of the mainline, and resolve each conflict with your
own judgement.

## Quick start

```bash
git status --short --branch
git branch "backup/$(git branch --show-current)/$(date +%Y%m%d-%H%M%S)"
git fetch origin && git rebase origin/<mainline>
```

* **DO** stop and tell me when the working tree holds changes of mine; they are mine to
  place, unless a rebase is in progress, when they are the conflict itself
* **DO** rebase onto `origin/<mainline>`; `git fetch` moves that ref, and leaves the local
  branch of the same name on the commit it already held
* **DO** make the backup branch; the verification below compares against it
* **DO** take the backup from the tip that git saved, when a rebase is already in progress;
  HEAD is detached, so `--show-current` prints nothing, and `ORIG_HEAD` can point at another
  commit after a reset:
  `git branch "backup/rebase/$(date +%Y%m%d-%H%M%S)" "$(cat "$(git rev-parse --git-path rebase-merge/orig-head)")"`
* **DO** rebase a branch that sits on another branch with `git rebase --onto
  origin/<mainline> <that branch>`; a plain rebase replays commits the mainline already
  holds another way

## How to resolve a conflict

```bash
git diff --name-only --diff-filter=U
git add <file>
GIT_EDITOR=true git rebase --continue
```

* **DO** set `GIT_EDITOR=true`; this environment shows no editor, and git waits forever
* **DO** resolve and `git add` every file the first command lists, then continue; git stops
  again at the next commit it cannot replay, so repeat the block until it reports success
* **DO** pick a side for a binary file on purpose, with `git checkout --theirs -- <file>` for
  my version or `--ours` for the mainline, before the `git add`; it holds no marker, and git
  leaves the mainline version in the tree for `git add` to keep
* **DO** stop and ask me when a resolution is unclear, and leave the rebase in progress;
  `git rebase --abort` loses each resolution that you made, so run it only when I say so

## How to verify

```bash
git log --format=%s origin/<mainline>..HEAD
git log --format=%s origin/<mainline>..<backup>
git grep -n "^<<<<<<< \|^>>>>>>> " HEAD
git diff origin/<mainline> HEAD
git diff <backup> HEAD
```

* **DO** account for each subject that the first two commands do not agree on; the rebase
  rewrote every hash, so the subjects are what compare. A subject that only the second prints
  is a commit that is gone: the mainline holds its patch already, `--onto` left it out, or a
  resolution emptied it, and git reports each case as success with an exit status of 0
* **DO** read the third command; git commits a marker I left behind and reports success
* **DO** account for each removed line in both diffs: in the first, one of my commits must
  remove it on purpose, and in the second, the mainline must be the cause; any other removed
  line is lost work
* **DO** run the build and the tests of the project; a commit that replays with no conflict
  can still use a name that the mainline changed. Put the fix in a new commit, and tell me
* **DO NOT** push, and **DO NOT** delete the backup branch, until I ask

## How to push

Push only when I ask, and only after the verification:

```bash
git push --force-with-lease --force-if-includes origin <branch>
```

* **DO** use both flags, and never `--force`; a rebase rewrites each commit, so a plain push is
  rejected. The lease refuses when the branch on `origin` moved after the fetch, and
  `--force-if-includes` refuses when the fetch brought a commit that this branch never held
* **DO** stop and tell me when git rejects the push; the branch on `origin` holds a commit of
  another session, and a forced push removes it

## Reference

A rebase replays my commits onto the mainline, so the sides are the opposite of a merge:

| Side | Marker | Content |
| --- | --- | --- |
| `--ours` | `<<<<<<< HEAD` | The mainline, and each commit of mine already replayed |
| `--theirs` | `>>>>>>> <commit>` | The commit of mine being replayed |

Files in this skill

  • README.md2 KB
  • SKILL.md4 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.