Sync Branch
Catch current branch up to base. Rebase only. Surface conflicts.
Flow
- Parallel:
git status --porcelaingit branch --show-currentgit rev-parse --abbrev-ref --symbolic-full-name @{u}(upstream if any)
- Base: user names one -> verbatim. Else detect:
git symbolic-ref --short refs/remotes/origin/HEAD-> strip theorigin/; ref missing ->git remote set-head origin -a, re-read; no remote ->main, fall backmaster. Why -> rebasing ontomainin adevelop-based repo replays the branch onto the wrong parent and manufactures conflicts that aren't real. - Dirty -> stash:
git stash push -u -m "sync-branch auto-stash". Pop later. Unsafe (unresolved merge) -> stop + tell user. - On base ->
git pull --ff-only origin <base>. Fails (local base diverged) -> stop + tell user. No auto-rebase of base itself. - Else:
git fetch origin <base>git rebase origin/<base>.
- Conflicts:
git status-> list conflicted paths.- Stop + surface. No auto-resolve.
- Tell user: resolve,
git add <paths>,git rebase --continue. Mentiongit rebase --abortescape. - Leave stash in place. Tell user to pop after resolve.
- Rebase done (clean or aborted) -> pop stash if created.
- Print one-liner: branch, base, commits replayed, force-push needed?
- 0 commits replayed (already up to date) -> say so explicitly; don't mention force-push (nothing rewritten).
Rules
- Always rebase, never merge. Why -> user workflow preference; linear history. Don't offer merge as alternative even on shared branches; surface the risk (
force-push needed) and let user decide. - Never force-push here. Pushed branch rebased -> tell user
git push --force-with-lease. Let user run. - Never
git rebase --skip/ drop commits to "make it work". Surface conflict. - Never
--no-verify. Why -> hooks gate broken state; skipping just defers the failure. - No upstream -> sync vs
origin/<base>. Note branch not pushed. - Pop stash you made on rebase clean OR abort. Pop blocked by conflicts -> leave stashed + tell user.