Context
- Current branch: !
git branch --show-current
- Trunk branch: !
git remote show origin 2>/dev/null | grep 'HEAD branch' | awk '{print $NF}' || echo "master"
- Remote refs available: !
git remote -v 2>/dev/null | head -2
- Commits on current branch not on trunk: !
TRUNK=$(git remote show origin 2>/dev/null | grep 'HEAD branch' | awk '{print $NF}' || echo "master"); git log --oneline "origin/${TRUNK}..HEAD" 2>/dev/null || echo "(could not determine commits ahead)"
- Diff from trunk (summary): !
TRUNK=$(git remote show origin 2>/dev/null | grep 'HEAD branch' | awk '{print $NF}' || echo "master"); git diff --stat "origin/${TRUNK}" 2>/dev/null || echo "(could not diff against trunk)"
Your Task
Rebase the current branch onto the remote trunk branch. Follow these steps carefully, handling each phase before moving to the next.
Phase 1: Detect trunk branch
Determine the trunk branch name from the context above (the "Trunk branch" value). Store it mentally as TRUNK. It will typically be master or main. If detection failed, try both origin/master and origin/main to see which exists.
Phase 2: Fetch latest and analyze
- Run
git fetch origin to get the latest remote state.
- Run
git diff origin/${TRUNK}...HEAD --stat to see what files the current branch modifies.
- Run
git diff origin/${TRUNK}...HEAD to see the full diff of changes on this branch.
- Run
git log --oneline origin/${TRUNK}..HEAD to see commits that will be rebased.
- Run
git diff origin/${TRUNK} -- $(git diff --name-only origin/${TRUNK}...HEAD) to check if trunk has also modified any of the same files — these are potential conflict zones.
Report a brief summary of:
- How many commits will be rebased
- Which files were changed on this branch
- Which of those files were ALSO changed on trunk (potential conflicts)
- An assessment of conflict likelihood (none expected / minor / significant)
Phase 3: Execute the rebase
Run:
git pull --rebase origin ${TRUNK} --autostash
If the rebase completes cleanly (exit code 0), skip to Phase 5.
Phase 4: Resolve conflicts (if any)
If conflicts are detected:
Run git status to see which files have conflicts.
For each conflicted file:
a. Read the file to see the conflict markers (<<<<<<<, =======, >>>>>>>)
b. Understand both sides of the conflict by examining what the branch intended vs what trunk changed
c. Resolve the conflict by editing the file — preserve the intent of BOTH changes when possible. When in doubt, prefer the branch's changes (our work) but integrate trunk's changes if they're structural (renames, new parameters, etc.)
d. Run git add <file> to mark it resolved
Before continuing the rebase, run the project's quality checks. Look for CLAUDE.md or AGENTS.md in the repo root to discover the project's required checks. Common quality gates by ecosystem:
| Gate |
Example commands |
| Formatter |
ruff format, prettier --write, rustfmt, gofmt |
| Linter |
ruff check --fix, eslint --fix, clippy, golangci-lint |
| Type checker |
mypy, tsc --noEmit, basedpyright |
| Tests |
pytest, jest, cargo test, go test ./... |
If any check fails, fix the issues and re-stage with git add before continuing.
Run git rebase --continue to proceed.
If more conflicts appear, repeat from step 1 of this phase.
If the rebase becomes unrecoverable, run git rebase --abort and report what went wrong.
Phase 5: Verify final state
After the rebase completes successfully:
- Run
git log --oneline -10 to confirm the rebased commit history looks correct.
- Run
git status to confirm a clean working tree.
- Run the project's quality checks one final time as described in Phase 4 step 3.
- Report the results: how many commits were rebased, whether any conflicts were resolved, and the final state of all quality checks.
Do NOT force-push. Only report the final state and let the user decide on the next step.
1---2name: rebase3description: Rebase current branch onto trunk (origin/master or origin/main), predict and resolve conflicts4---56## Context78- Current branch: !`git branch --show-current`9- Trunk branch: !`git remote show origin 2>/dev/null | grep 'HEAD branch' | awk '{print $NF}' || echo "master"`10- Remote refs available: !`git remote -v 2>/dev/null | head -2`11- Commits on current branch not on trunk: !`TRUNK=$(git remote show origin 2>/dev/null | grep 'HEAD branch' | awk '{print $NF}' || echo "master"); git log --oneline "origin/${TRUNK}..HEAD" 2>/dev/null || echo "(could not determine commits ahead)"`12- Diff from trunk (summary): !`TRUNK=$(git remote show origin 2>/dev/null | grep 'HEAD branch' | awk '{print $NF}' || echo "master"); git diff --stat "origin/${TRUNK}" 2>/dev/null || echo "(could not diff against trunk)"`1314## Your Task1516Rebase the current branch onto the remote trunk branch. Follow these steps carefully, handling each phase before moving to the next.1718### Phase 1: Detect trunk branch1920Determine the trunk branch name from the context above (the "Trunk branch" value). Store it mentally as `TRUNK`. It will typically be `master` or `main`. If detection failed, try both `origin/master` and `origin/main` to see which exists.2122### Phase 2: Fetch latest and analyze23241. Run `git fetch origin` to get the latest remote state.252. Run `git diff origin/${TRUNK}...HEAD --stat` to see what files the current branch modifies.263. Run `git diff origin/${TRUNK}...HEAD` to see the full diff of changes on this branch.274. Run `git log --oneline origin/${TRUNK}..HEAD` to see commits that will be rebased.285. Run `git diff origin/${TRUNK} -- $(git diff --name-only origin/${TRUNK}...HEAD)` to check if trunk has also modified any of the same files — these are potential conflict zones.2930Report a brief summary of:31- How many commits will be rebased32- Which files were changed on this branch33- Which of those files were ALSO changed on trunk (potential conflicts)34- An assessment of conflict likelihood (none expected / minor / significant)3536### Phase 3: Execute the rebase3738Run:39```40git pull --rebase origin ${TRUNK} --autostash41```4243If the rebase completes cleanly (exit code 0), skip to Phase 5.4445### Phase 4: Resolve conflicts (if any)4647If conflicts are detected:48491. Run `git status` to see which files have conflicts.502. For each conflicted file:51 a. Read the file to see the conflict markers (`<<<<<<<`, `=======`, `>>>>>>>`)52 b. Understand both sides of the conflict by examining what the branch intended vs what trunk changed53 c. Resolve the conflict by editing the file — preserve the intent of BOTH changes when possible. When in doubt, prefer the branch's changes (our work) but integrate trunk's changes if they're structural (renames, new parameters, etc.)54 d. Run `git add <file>` to mark it resolved553. Before continuing the rebase, run the project's quality checks. Look for CLAUDE.md or AGENTS.md in the repo root to discover the project's required checks. Common quality gates by ecosystem:5657 | Gate | Example commands |58 |------|-----------------|59 | Formatter | `ruff format`, `prettier --write`, `rustfmt`, `gofmt` |60 | Linter | `ruff check --fix`, `eslint --fix`, `clippy`, `golangci-lint` |61 | Type checker | `mypy`, `tsc --noEmit`, `basedpyright` |62 | Tests | `pytest`, `jest`, `cargo test`, `go test ./...` |6364 If any check fails, fix the issues and re-stage with `git add` before continuing.654. Run `git rebase --continue` to proceed.665. If more conflicts appear, repeat from step 1 of this phase.676. If the rebase becomes unrecoverable, run `git rebase --abort` and report what went wrong.6869### Phase 5: Verify final state7071After the rebase completes successfully:72731. Run `git log --oneline -10` to confirm the rebased commit history looks correct.742. Run `git status` to confirm a clean working tree.753. Run the project's quality checks one final time as described in Phase 4 step 3.764. Report the results: how many commits were rebased, whether any conflicts were resolved, and the final state of all quality checks.7778Do NOT force-push. Only report the final state and let the user decide on the next step.