sync-branch · softaworks — Claude Code command: sync feature branch with main
Claude Code command that syncs a feature branch with the latest main via rebase. Runs on /sync-branch and updates the PR with force-push.
MIT ★ 2,707 updated 2026-03-05
.claude/commands/sync-branch.mdWhat sync-branch does
The command fetches latest commits from origin, rebases the current branch onto main (or another branch if you pass an argument), and pushes changes back with git push --force-with-lease. Works with Claude Code, Codex, GitHub Copilot and Gemini CLI — each has its own install path.
Rebase may hit conflicts — the command stops and you resolve them manually. After that, force-push updates the remote branch and the PR. Force-with-lease is safer than plain force, but still rewrites history — avoid it on branches where others are working.
What it helps with
- bring a feature branch up to date before merging
- pull fresh commits from main into an active branch
- update a PR after rebase
- sync multiple feature branches with a shared base
Example prompts for the agent
- Sync the current branch with
main - Run
/sync-branchto update the PR - Rebase onto
developinstead ofmain
How to install sync-branch
Manually: put the files in place
.claude/commands/sync-branch.mdCall it with /sync-branch. For all projects use ~/.claude/commands/
Manually: put the files in place
~/.codex/prompts/sync-branch.mdCall it with /prompts:sync-branch. Codex marks this format deprecated in favour of skills
Manually: put the files in place
.github/prompts/sync-branch.prompt.mdManually: put the files in place
.gemini/commands/sync-branch.tomlGemini stores commands as TOML: the prompt text goes into the prompt field
Questions about sync-branch
How do I install sync-branch in Claude Code?
Put the file in .claude/commands/sync-branch.md — the command will appear in the available list.
What does sync-branch do?
The command syncs a feature branch with the latest main via rebase and updates the PR with force-push. You can pass a different target branch as an argument.
What is force-with-lease?
A safer variant of --force: push succeeds only if the remote branch has not changed since the last fetch. Protects against accidentally overwriting someone else's commits.
Source text
sync-branch.md · MIT
---
description: Sync feature branch with the latest main branch.
argument-hint: [target]
---
1. Fetch latest upstream refs: `git fetch origin --prune`.
2. Identify target branch (default `main`, or override via argument).
3. Rebase current branch onto target:
```bash
git rebase origin/${target:-main}
```
4. Resolve any conflicts
5. Force-with-lease push to update the PR:
```bash
git push --force-with-lease origin $(git branch --show-current)
```
© softaworks · MIT · softaworks/agent-toolkit
Similar slash commands
All slash commands for Git and GitHub →sync-branch by other authors comes first.