{"data":{"slug":"discovered-38912bbed71033dd7752ce93b9aac4a6f4f0e4a17833e04e","title":"Rebase a GitLab MR branch onto the latest target branch","summary":"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.","url":"https:\/\/skillshunter.net\/skills\/discovered-38912bbed71033dd7752ce93b9aac4a6f4f0e4a17833e04e","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/discovered-38912bbed71033dd7752ce93b9aac4a6f4f0e4a17833e04e","markdown_url":"https:\/\/skillshunter.net\/skills\/discovered-38912bbed71033dd7752ce93b9aac4a6f4f0e4a17833e04e.md","download_url":"https:\/\/skillshunter.net\/skills\/discovered-38912bbed71033dd7752ce93b9aac4a6f4f0e4a17833e04e\/download","category":{"slug":"software-development","name":"Software & Development"},"editor_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`.","instructions":"---\nname: rebase\ndescription: 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\".\nargument-hint: \"[mr-url-or-iid]\"\n---\n\n# Rebase\n\nBring one MR branch up to date with its target and resolve the conflicts.\nThis works from any workflow state. Afterwards the MR is in \"Undraft, skip\nCI\": `[ci skip]` is back in the title and the bots review the new head next.\n\nThe target is `$ARGUMENTS`. If it's empty, use the current branch's MR. Run\nfrom that branch's worktree. The `rebase` shortcut opens one.\n\nThe invocation authorizes the local rebase and the checks. Get one\nconfirmation (step 5) before the push and the MR edits.\n\n## 1. Preflight\n\nBefore anything else, check that the MR is yours:\n\n```sh\n~\/.claude\/skills\/glab-read\/scripts\/glab-read.py mine <iid> [-R <group>\/<project>]\n```\n\nIf it exits 1, stop and show its line, which names the author and the\ntitle. A mistyped IID is the usual cause.\n\n```sh\ngit status --porcelain\nglab-read.py mr <iid> --fields iid,draft,title,source_branch,target_branch,sha\ngit fetch origin\n```\n\nStop if the working tree is dirty, or if `HEAD` isn't the branch the MR names.\nStop if `HEAD` and `origin\/<source_branch>` differ. Unpushed commits or someone\nelse's push would make the force-push overwrite work, so ask which one wins.\nRecord `HEAD` as `<old-head>`. The push lease uses it.\n\n## 2. Pick the base\n\nMost MRs rebase onto `origin\/<target_branch>`. A stacked branch needs more\ncare.\n\n- **Target is a live parent branch.** Rebase onto `origin\/<target_branch>`,\n  not main. The parent rebases on its own.\n- **The parent was squash-merged.** This applies when the target is main but\n  the branch still carries the parent's commits, or when the target branch is\n  gone from origin. A plain rebase would replay the parent's commits on top of\n  their own squash commit and conflict with itself. Find the parent's last\n  commit by asking GitLab which MRs contain each commit:\n\n  ```sh\n  for c in $(git rev-list origin\/main..HEAD); do\n    glab api \"projects\/<enc>\/repository\/commits\/$c\/merge_requests\" \\\n      | jq -r --arg c \"$c\" '.[] | select(.state==\"merged\") | \"\\($c) !\\(.iid)\"'\n  done\n  ```\n\n  The newest listed commit is `<old-parent-tip>`. Rebase with\n  `git rebase --onto origin\/main <old-parent-tip>`. If the MR still targets\n  the merged parent's branch, the target must change to main in step 5.\n\nRecord the base you used and the old base (`git merge-base <old-head> <base>`)\nfor the range-diff in step 4.\n\n## 3. Rebase and resolve\n\nRun the rebase. For each conflict, settle it by what each side meant.\n\n- Read this MR's intent from its description and the commit being replayed.\n  Read the other side's intent from the target commits that touched the file\n  (`git log <old-base>..<base> -- <file>`).\n- Keep both changes when they're independent. When the upstream side renamed,\n  moved, or re-signatured something this branch uses, carry the branch's change\n  onto the new shape.\n- Regenerate generated files rather than hand-merging them: `go mod tidy` for\n  `go.sum`, and the repo's generator for generated code.\n- Stop and ask when both sides changed behavior in the same place and neither\n  intent settles it. Show both hunks and what each was for.\n\nNever use `-X ours`\/`-X theirs`, `git rebase --skip`, or `git checkout\n--ours\/--theirs` on a whole file. Each of them drops one side's work silently.\nRecord one line per resolved hunk for the report.\n\n## 4. Check\n\nA rebase can apply cleanly and still break the build, and the push skips CI.\nSo check locally:\n\n```sh\ngo build .\/...\ngo vet <pkgs> && go test <pkgs>\n```\n\n`<pkgs>` covers the packages this MR changes (`git diff --name-only\n<base>...HEAD`) and the packages of every file you resolved. If a test needs a\nservice that isn't running, name it as skipped. Don't count it as passing.\nFix a failure the rebase caused in a new commit on top. MRs squash on merge,\nso it doesn't need folding in. Ask about any other failure.\n\nThen confirm that the branch's own change survived:\n\n```sh\ngit range-diff <old-base>..<old-head> <base>..HEAD\n```\n\nAny commit whose patch changed beyond your resolutions means something went\nwrong. Explain it or stop.\n\n## 5. Push and return to \"Undraft, skip CI\"\n\nAsk once with `AskUserQuestion`, and list every write:\n\n- `git push --force-with-lease=<source_branch>:<old-head> -o ci.skip origin HEAD`\n- set the title to `[ci skip] <title>` if it has no `[ci skip]` or\n  `[skip ci]` anywhere. Danger appends `[skip ci]` to a stacked MR, and that\n  one counts. Keep a `Draft:` prefix ahead of it.\n- the target branch change to main, when step 2 found a merged parent.\n- for a Draft MR, mark it ready or keep it Draft. A Draft MR hasn't entered\n  the bot loop yet, so recommend keeping it.\n\nMake the MR edits with `glab api -X PUT projects\/<enc>\/merge_requests\/<iid>`,\nthen read the MR back and confirm each field changed. `glab mr update` can\nexit 0 without applying a field.\n\n## Report\n\n- the base, and whether `--onto` cut out a merged parent\n- each resolved hunk in one line: file, what each side did, what you kept\n- the build and test results, with skipped tests named\n- whether the range-diff came out clean\n- what was pushed and edited\n\nBot reviews of the old head are now stale, so `\/check-bot-reviews` reports\n`stale` until the bots review the new head.\n","use_cases":["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"],"limitations":[],"compatibility":[],"setup_tip":null,"sample_input":null,"sample_output":null,"source_url":"https:\/\/gitlab.com\/radbatnag\/claude-skills\/-\/blob\/05b55872e4e98b79bc052be748b3abd6dccbabe6\/skills\/rebase\/SKILL.md","source_commit":"05b55872e4e98b79bc052be748b3abd6dccbabe6","license":null,"version":null,"listing_approved_at":"2026-11-28","created_at":"2026-11-28T08:00:12.000000Z","updated_at":"2026-11-28T18:37:52.000000Z","seo_title":"Rebase GitLab MR Branch","seo_description":"Rebase a GitLab Merge Request branch onto the latest target branch, resolve conflicts by intent, and force-push with CI skipped.","seo_keywords":["git rebase","gitlab mr rebase","resolve merge conflicts","force push gitlab","ci skip gitlab"]}}