| name | rebase |
| description | Rebases the current branch onto origin/main, resolves rebase conflicts, and force-pushes with lease using non-interactive Git commands that never open an editor. Use when updating a feature branch from main, handling rebase conflicts, or rewriting branch history before updating a pull request. |
Rebase
Rebase the current branch on origin/main, resolve conflicts, and force-push
the rewritten history without opening an editor.
Contents
How to use this skill
Attach this file to your Copilot Chat context, then invoke it when the current
branch needs to be rebased onto origin/main and pushed.
Related skills
Prerequisites
git is installed and authenticated for the remote.
- The branch is a topic branch with an upstream on
origin.
- The working tree is clean before rebasing.
Safety rules
These rules are mandatory:
- Never run this workflow on
main or 4.x.
- Always fetch
origin immediately before rebasing.
- Always run rebase commands with
GIT_EDITOR=: and GIT_SEQUENCE_EDITOR=: so
no editor opens.
- Force-push only with
--force-with-lease.
Workflow
- Preflight checks and fetch
- Start rebase on origin/main
- Resolve conflicts and continue
- Verify the rebased branch
- Force-push with lease
Step 1: Preflight checks and fetch
git branch --show-current
git status --short --branch
git fetch --prune origin
If the current branch is main or 4.x, stop and ask the user to switch to a
topic branch first.
If git status --short --branch shows uncommitted changes, stop and ask the
user whether to commit or stash before continuing.
Step 2: Start rebase on origin/main
GIT_EDITOR=: GIT_SEQUENCE_EDITOR=: git rebase origin/main
If the command succeeds, continue to Step 4. If it stops with conflicts, go to
Step 3.
Step 3: Resolve conflicts and continue
Repeat until the rebase completes:
-
Inspect conflicted files:
git status --short
-
Edit conflicted files, remove conflict markers, and keep the intended final
content.
-
Stage resolved files:
git add <resolved-path> [<resolved-path>...]
-
Continue the rebase without opening an editor:
GIT_EDITOR=: GIT_SEQUENCE_EDITOR=: git rebase --continue
-
If Git reports an empty patch after conflict resolution, skip that commit:
GIT_EDITOR=: GIT_SEQUENCE_EDITOR=: git rebase --skip
If the rebase cannot be completed safely, abort and report back:
git rebase --abort
Step 4: Verify the rebased branch
git status --short --branch
git merge-base --is-ancestor origin/main HEAD
git --no-pager log --oneline --decorate --max-count=15
git merge-base --is-ancestor origin/main HEAD must exit successfully.
Step 5: Force-push with lease
git push --force-with-lease
If push is rejected, fetch and reconcile remote updates before retrying. Never
replace this with plain --force.
Troubleshooting
| Issue | Solution |
|---|
| Rebase stops with conflicts | Resolve files, git add, then run GIT_EDITOR=: GIT_SEQUENCE_EDITOR=: git rebase --continue. |
| Rebase continue opens an editor | Re-run with both GIT_EDITOR=: and GIT_SEQUENCE_EDITOR=: prefixes. |
--force-with-lease push rejected | Run git fetch origin, inspect divergence, reconcile, and retry --force-with-lease. |
| Need to abandon rebasing attempt | Run git rebase --abort and report the reason to the user. |