Skip to content

commandGit and releases

Git Sync

Brings your current branch up to date with its upstream by rebase or merge, resolves small conflicts and reports what changed.

npx workspacetemplates add git-sync --tool claude-code

Writes 1 file to .claude/commands/

.claude/commands/git-sync.md14 lines · 1.1 KBFile
---
description: Brings your current branch up to date with its upstream by rebase or merge, resolves small conflicts and reports what changed.
argument-hint: "[branch to sync with, default upstream]"
---

Sync the current branch with: $ARGUMENTS (its upstream, or origin/main if none).

1. Run `git status` and stop if the tree is dirty; offer `git stash` and wait for approval. Run `git fetch --all --prune`.
2. Show `git rev-list --left-right --count HEAD...<target>` and the incoming commit subjects.
3. Choose the method. Rebase if the branch is local or has only your commits. Merge if the branch is pushed and others may have based work on it. State the choice and why.
4. Run it. On conflict, list the files; resolve only trivial ones (imports, whitespace, adjacent edits) and explain each. Stop and ask on anything touching logic. Never use `--strategy-option theirs` or `ours` blindly.
5. After a rebase, run the tests. Do not push. If the branch was already pushed and you rebased, say that a `--force-with-lease` push is needed and wait for the user to ask for it.

Report commits applied, files changed upstream, conflicts resolved, and the test result.

What it does

Falling behind the main branch is routine, and so is picking the wrong way to catch up. This command checks the state of your branch, chooses rebase or merge based on whether the branch is already shared, and does the update.

Simple conflicts are resolved with an explanation. Anything involving real logic is shown to you instead of guessed.

Example

you › /git-sync origin/main

agent › Fetched. 7 commits behind, 2 ahead. Branch is unpushed, so I rebased onto origin/main.
Conflict in src/api/client.ts (import order only): resolved. Tests pass.
Upstream touched: billing/*, 3 test files, package.json (new dependency date-fns). Push needs --force-with-lease only if you pushed before.

Questions

Will it push for me?
No. It updates your local branch and tells you if a force push would be needed, which stays your decision.
How does it choose between rebase and merge?
By whether the branch has been shared. Private branches get a clean rebase, shared ones get a merge so nobody rewrites history others rely on.
  • Branch Cleanup

    CommandGit and releases

    Free
  • Changelog Entry

    CommandGit and releases

    Free
  • Cherry Pick Fix

    CommandGit and releases

    Free
  • Commit Message

    CommandGit and releases

    Free