Approved catalog listing
SKILL #3010
skillshunter.net
Home / Software & Development / Rebase a GitLab MR branch onto the latest target branch
Listing Approved Approved on: November 28, 2026

Rebase a GitLab MR branch onto the latest target branch

Rebase a GitLab Merge Request (MR) branch onto the latest target branch (usually main), resolve conflicts by intent, check the build, and force-push with CI skipped, returning the MR to the "[ci skip]" bot-review state.

Rate this skill

No ratings yet

Editor's Note

Before running, ensure the MR is yours by checking with `glab-read.py mine <iid>`. Confirm the working tree is clean and `HEAD` matches the MR's branch. If the parent branch was squash-merged, identify the parent's last commit using GitLab's API and rebase onto `origin/main`.

When to Use It

  • Rebase an MR branch against the latest main branch
  • Resolve merge conflicts in a GitLab MR
  • Update a stacked MR branch after its parent was squash-merged

SKILL.md

SkillsHunter provides this listing for informational purposes only. Review the skill’s source, license, and required permissions before use. You are responsible for deciding whether to install or run it. Terms of Use

↓ Download .md

Rebase

Bring one MR branch up to date with its target and resolve the conflicts. This works from any workflow state. Afterwards the MR is in "Undraft, skip CI": [ci skip] is back in the title and the bots review the new head next.

The target is $ARGUMENTS. If it's empty, use the current branch's MR. Run from that branch's worktree. The rebase shortcut opens one.

The invocation authorizes the local rebase and the checks. Get one confirmation (step 5) before the push and the MR edits.

1. Preflight

Before anything else, check that the MR is yours:

~/.claude/skills/glab-read/scripts/glab-read.py mine <iid> [-R <group>/<project>]

If it exits 1, stop and show its line, which names the author and the title. A mistyped IID is the usual cause.

git status --porcelain
glab-read.py mr <iid> --fields iid,draft,title,source_branch,target_branch,sha
git fetch origin

Stop if the working tree is dirty, or if HEAD isn't the branch the MR names. Stop if HEAD and origin/<source_branch> differ. Unpushed commits or someone else's push would make the force-push overwrite work, so ask which one wins. Record HEAD as <old-head>. The push lease uses it.

2. Pick the base

Most MRs rebase onto origin/<target_branch>. A stacked branch needs more care.

  • Target is a live parent branch. Rebase onto origin/<target_branch>, not main. The parent rebases on its own.

  • The parent was squash-merged. This applies when the target is main but the branch still carries the parent's commits, or when the target branch is gone from origin. A plain rebase would replay the parent's commits on top of their own squash commit and conflict with itself. Find the parent's last commit by asking GitLab which MRs contain each commit:

    for c in $(git rev-list origin/main..HEAD); do
      glab api "projects/<enc>/repository/commits/$c/merge_requests" \
        | jq -r --arg c "$c" '.[] | select(.state=="merged") | "\($c) !\(.iid)"'
    done
    

    The newest listed commit is <old-parent-tip>. Rebase with git rebase --onto origin/main <old-parent-tip>. If the MR still targets the merged parent's branch, the target must change to main in step 5.

Record the base you used and the old base (git merge-base <old-head> <base>) for the range-diff in step 4.

3. Rebase and resolve

Run the rebase. For each conflict, settle it by what each side meant.

  • Read this MR's intent from its description and the commit being replayed. Read the other side's intent from the target commits that touched the file (git log <old-base>..<base> -- <file>).
  • Keep both changes when they're independent. When the upstream side renamed, moved, or re-signatured something this branch uses, carry the branch's change onto the new shape.
  • Regenerate generated files rather than hand-merging them: go mod tidy for go.sum, and the repo's generator for generated code.
  • Stop and ask when both sides changed behavior in the same place and neither intent settles it. Show both hunks and what each was for.

Never use -X ours/-X theirs, git rebase --skip, or git checkout --ours/--theirs on a whole file. Each of them drops one side's work silently. Record one line per resolved hunk for the report.

4. Check

A rebase can apply cleanly and still break the build, and the push skips CI. So check locally:

go build ./...
go vet <pkgs> && go test <pkgs>

<pkgs> covers the packages this MR changes (`git diff --name-only

Then confirm that the branch's own change survived:

git range-diff <old-base>..<old-head> <base>..HEAD

Any commit whose patch changed beyond your resolutions means something went wrong. Explain it or stop.

5. Push and return to "Undraft, skip CI"

Ask once with AskUserQuestion, and list every write:

  • git push --force-with-lease=<source_branch>:<old-head> -o ci.skip origin HEAD
  • set the title to [ci skip] <title> if it has no [ci skip] or [skip ci] anywhere. Danger appends [skip ci] to a stacked MR, and that one counts. Keep a Draft: prefix ahead of it.
  • the target branch change to main, when step 2 found a merged parent.
  • for a Draft MR, mark it ready or keep it Draft. A Draft MR hasn't entered the bot loop yet, so recommend keeping it.

Make the MR edits with glab api -X PUT projects/<enc>/merge_requests/<iid>, then read the MR back and confirm each field changed. glab mr update can exit 0 without applying a field.

Report

  • the base, and whether --onto cut out a merged parent
  • each resolved hunk in one line: file, what each side did, what you kept
  • the build and test results, with skipped tests named
  • whether the range-diff came out clean
  • what was pushed and edited

Bot reviews of the old head are now stale, so /check-bot-reviews reports stale until the bots review the new head.

View original Markdown
---
name: rebase
description: Rebase one of my GitLab MR branches onto the latest target branch (usually main), resolve the conflicts by intent, check the build, then force-push with CI skipped and put the MR back in the "[ci skip]" bot-review state. Handles a stacked branch whose parent was squash-merged. Use for /rebase, "rebase against latest main", "resolve the conflicts", "the MR has merge conflicts".
argument-hint: "[mr-url-or-iid]"
---

# Rebase

Bring one MR branch up to date with its target and resolve the conflicts.
This works from any workflow state. Afterwards the MR is in "Undraft, skip
CI": `[ci skip]` is back in the title and the bots review the new head next.

The target is `$ARGUMENTS`. If it's empty, use the current branch's MR. Run
from that branch's worktree. The `rebase` shortcut opens one.

The invocation authorizes the local rebase and the checks. Get one
confirmation (step 5) before the push and the MR edits.

## 1. Preflight

Before anything else, check that the MR is yours:

```sh
~/.claude/skills/glab-read/scripts/glab-read.py mine <iid> [-R <group>/<project>]
```

If it exits 1, stop and show its line, which names the author and the
title. A mistyped IID is the usual cause.

```sh
git status --porcelain
glab-read.py mr <iid> --fields iid,draft,title,source_branch,target_branch,sha
git fetch origin
```

Stop if the working tree is dirty, or if `HEAD` isn't the branch the MR names.
Stop if `HEAD` and `origin/<source_branch>` differ. Unpushed commits or someone
else's push would make the force-push overwrite work, so ask which one wins.
Record `HEAD` as `<old-head>`. The push lease uses it.

## 2. Pick the base

Most MRs rebase onto `origin/<target_branch>`. A stacked branch needs more
care.

- **Target is a live parent branch.** Rebase onto `origin/<target_branch>`,
  not main. The parent rebases on its own.
- **The parent was squash-merged.** This applies when the target is main but
  the branch still carries the parent's commits, or when the target branch is
  gone from origin. A plain rebase would replay the parent's commits on top of
  their own squash commit and conflict with itself. Find the parent's last
  commit by asking GitLab which MRs contain each commit:

  ```sh
  for c in $(git rev-list origin/main..HEAD); do
    glab api "projects/<enc>/repository/commits/$c/merge_requests" \
      | jq -r --arg c "$c" '.[] | select(.state=="merged") | "\($c) !\(.iid)"'
  done
  ```

  The newest listed commit is `<old-parent-tip>`. Rebase with
  `git rebase --onto origin/main <old-parent-tip>`. If the MR still targets
  the merged parent's branch, the target must change to main in step 5.

Record the base you used and the old base (`git merge-base <old-head> <base>`)
for the range-diff in step 4.

## 3. Rebase and resolve

Run the rebase. For each conflict, settle it by what each side meant.

- Read this MR's intent from its description and the commit being replayed.
  Read the other side's intent from the target commits that touched the file
  (`git log <old-base>..<base> -- <file>`).
- Keep both changes when they're independent. When the upstream side renamed,
  moved, or re-signatured something this branch uses, carry the branch's change
  onto the new shape.
- Regenerate generated files rather than hand-merging them: `go mod tidy` for
  `go.sum`, and the repo's generator for generated code.
- Stop and ask when both sides changed behavior in the same place and neither
  intent settles it. Show both hunks and what each was for.

Never use `-X ours`/`-X theirs`, `git rebase --skip`, or `git checkout
--ours/--theirs` on a whole file. Each of them drops one side's work silently.
Record one line per resolved hunk for the report.

## 4. Check

A rebase can apply cleanly and still break the build, and the push skips CI.
So check locally:

```sh
go build ./...
go vet <pkgs> && go test <pkgs>
```

`<pkgs>` covers the packages this MR changes (`git diff --name-only
<base>...HEAD`) and the packages of every file you resolved. If a test needs a
service that isn't running, name it as skipped. Don't count it as passing.
Fix a failure the rebase caused in a new commit on top. MRs squash on merge,
so it doesn't need folding in. Ask about any other failure.

Then confirm that the branch's own change survived:

```sh
git range-diff <old-base>..<old-head> <base>..HEAD
```

Any commit whose patch changed beyond your resolutions means something went
wrong. Explain it or stop.

## 5. Push and return to "Undraft, skip CI"

Ask once with `AskUserQuestion`, and list every write:

- `git push --force-with-lease=<source_branch>:<old-head> -o ci.skip origin HEAD`
- set the title to `[ci skip] <title>` if it has no `[ci skip]` or
  `[skip ci]` anywhere. Danger appends `[skip ci]` to a stacked MR, and that
  one counts. Keep a `Draft:` prefix ahead of it.
- the target branch change to main, when step 2 found a merged parent.
- for a Draft MR, mark it ready or keep it Draft. A Draft MR hasn't entered
  the bot loop yet, so recommend keeping it.

Make the MR edits with `glab api -X PUT projects/<enc>/merge_requests/<iid>`,
then read the MR back and confirm each field changed. `glab mr update` can
exit 0 without applying a field.

## Report

- the base, and whether `--onto` cut out a merged parent
- each resolved hunk in one line: file, what each side did, what you kept
- the build and test results, with skipped tests named
- whether the range-diff came out clean
- what was pushed and edited

Bot reviews of the old head are now stale, so `/check-bot-reviews` reports
`stale` until the bots review the new head.

Community Reviews & Field Notes

Tried this skill on your own project? Share the model you used and the results you got.

Add Your Review

Approved reviews appear publicly with the name or role you enter. See the Privacy Notice.