sync-branch · cloudai-x — Claude Code slash command: sync a branch with main
sync-branch fetches origin, then rebases or merges the default branch into your current one, stashing uncommitted work first. Useful right before a push or a pull request.
MIT ★ 1,424 updated 2026-10-06
.claude/commands/sync-branch.mdWhat sync-branch does
Run it and the command goes through a fixed order: check git status, stash anything uncommitted, git fetch, then rebase onto origin/<default-branch>. Pass merge if you want a merge commit instead.
Before touching anything it gathers context: the branch you are on, the default branch reported by git remote show origin, changed files, the ahead/behind count against origin/HEAD, and the configured remotes. Its only allowed tool is Bash(git:*), so nothing outside git runs.
With no argument you get a rebase. Conflicts are listed, not fixed, and you resolve them yourself. Stashed changes come back at the end.
What it helps with
- Pull the latest main into a feature branch before pushing
- Stash unfinished edits and get them back after the sync
- See how far a branch has drifted from origin
- Switch to a merge commit instead of a rebase with one argument
- Get a list of conflicting files after syncing
Example prompts for the agent
- Sync my current branch with main using rebase
- Run
/sync-branch merge, I want a merge commit here - Run
/sync-branchand tell me which files conflict
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 command file at .claude/commands/sync-branch.md inside your project. It then runs as /sync-branch.
What does sync-branch do?
It fetches from origin and brings the default branch into your current one, rebasing unless you ask for a merge. Uncommitted edits wait in a stash meanwhile.
Does it resolve merge conflicts?
No. It reports them and stops, so you fix them by hand. The only tool it may call is Bash(git:*).
Source text
sync-branch.md · MIT
--- allowed-tools: Bash(git:*) description: Sync current branch with main/master (fetch, rebase or merge) argument-hint: "[merge|rebase] (default: rebase)" --- ## Context - Current branch: !`git branch --show-current` - Default branch: !`git remote show origin 2>/dev/null | grep 'HEAD branch' | cut -d' ' -f5 || echo "main"` - Uncommitted changes: !`git status --porcelain` - Commits behind/ahead of origin's default branch: !`git rev-list --left-right --count origin/HEAD...HEAD 2>/dev/null || echo "unknown"` - Current remote: !`git remote -v | head -2` ## Task Safely sync the current branch with the default branch: 1. Check for uncommitted changes - if any, stash them 2. Fetch the latest from origin 3. Based on argument (default: rebase): - **rebase**: `git rebase origin/<default-branch>` - **merge**: `git merge origin/<default-branch>` 4. Handle any conflicts by reporting them clearly 5. If changes were stashed, pop them 6. Report the sync status Strategy: $ARGUMENTS
© CloudAI-X · MIT · CloudAI-X/claude-workflow-v2
Similar slash commands
All slash commands for Git and GitHub →sync-branch by other authors comes first.