Keep Git branch rebased and in sync

VerifiedSafe

Keeps the current branch rebased on its base branch and the worktree clean, with sync cadence, pre-rebase backup, and hunk-by-hunk conflict resolution.

Sby Skills Guide Bot
DevelopmentIntermediate
9/18/2026
Claude Code
#git-rebase#branch-sync#merge-conflicts#version-control#workflow

Recommended for

Automated summary

Keeps the current branch rebased on its base branch and the worktree clean through a repeatable Git sync and conflict-resolution loop.

Strengths

  • Makes rebasing routine maintenance at session start, after commits, and before PRs.
  • Adds practical safeguards: backup branches, rerere, and force-with-lease plus force-if-includes pushes.
  • Requires lint and non-watch tests after conflicts or large rebases, with guidance for finding CI-safe commands.
  • Gives explicit conflict rules that avoid blanket ours/theirs resolution and skipping commits.

Limitations

  • Assumes Git CLI and Bash; does not address GUI Git clients.
  • Base branch and test commands are inferred from repo docs or user input, so setup may need clarification.
  • Leaves ambiguous conflict decisions to the user and warns against force-pushing shared branches.
When to use it

Use at session start, after a commit, before opening or updating a PR, or whenever the branch has fallen behind its base.

When not to use it

Avoid on shared branches or when rewriting history requires approval you do not have.

Security analysis

Safe
Quality score92/100

The skill instructs only legitimate Git maintenance commands (fetch, rebase, stash, push with force-with-lease and force-if-includes). It explicitly forbids dangerous operations like plain force push, reset --hard on dirty trees, and git add -A. No exfiltration, destructive system commands, or obfuscation are present.

No concerns found

How this analysis is made

Examples

Sync with main
Sync my current branch with origin/main, rebase any upstream changes, and leave the worktree clean.
Resolve rebase conflicts
My branch has conflicts rebasing onto main. Resolve them hunk by hunk, continue the rebase, and run lint and tests afterward.
Pre-PR check
Am I up to date with the base branch? Rebase if needed before I open the PR, and report the status in one line.

name: git-sync description: Keep the current branch rebased on its base branch and the worktree clean. Use at session start, after each commit, before opening or updating a PR, when a rebase conflicts, or when the user says "rebase", "sync", "am I up to date", "merge main". allowed-tools: Bash, Read, Edit, Grep, Glob

Rebase is maintenance, not a finishing move. Keep a short leash: never more than a few base commits behind, never more than one unit of work in the tree.

Setup, once per session

git rev-parse --abbrev-ref HEAD                     # abort if this IS the base branch
git config rerere.enabled true                      # replays resolutions you already made
git remote set-head origin -a                       # only if origin/HEAD is missing (fresh CI clone)
git symbolic-ref --short refs/remotes/origin/HEAD   # -> origin/<default>

<base> precedence: user's answer > repo docs (CLAUDE.md, AGENTS.md, CONTRIBUTING.md) > open PR's baseRefName > origin/HEAD. None resolve → ask.

Find lint/test commands the same way (package.json scripts, Makefile, justfile) and require a non-watch variant: test is often jest --watch and never returns. Take the test-ci-style script, or force --watchAll=false / CI=true. None found → say so, don't skip silently.

Cadence

Run the loop unprompted at: session start, after each commit, before push/PR, on staleness (upstream touched your files, CI conflicts, user mentions a merged PR).

Between syncs, commit each coherent unit as soon as it works — repo's commit convention, git log --oneline if undocumented. One dirty tree holding three unrelated changes = a three-front conflict.

Loop

git status --short                         # clean, else: git stash push -u   (-u, or untracked files break the rebase)
git fetch origin <base>
git rev-list --count HEAD..origin/<base>   # 0 -> nothing to do, stop here
git branch -f backup/<branch>              # net: a bad rebase undoes with git reset --hard backup/<branch>
git rebase origin/<base>
git rev-list --count HEAD..origin/<base>   # back to 0? if not, upstream moved — run the loop again

Stashed → git stash pop, re-check status.

Done when: the second counter reads 0, git status is clean, no .orig/.rej left.

Conflict resolved or >10 commits absorbed → run lint + the non-watch tests. A rebase lands code that never compiled against the new base.

Conflicts

Resolve now, hunk by hunk, while the work is still in your head.

  • Read both sides, understand why the base changed. Never blanket --ours/--theirs.
  • git add <file> → GIT_EDITOR=true git rebase --continue. Without GIT_EDITOR=true the editor opens and hangs a non-interactive shell, leaving the rebase half-done.
  • Never --skip — it drops one of your commits.
  • A branch far behind conflicts on many commits in a row. That is the normal cost: persevere commit by commit, rerere replays the repeats. Never squash your own commits just to shorten a rebase.
  • git rebase --abort restores the pre-rebase state exactly. Use it and ask only on substance: the conflict touches logic you can't attribute, or resolving means rewriting someone else's change.
  • Then read git diff origin/<base>...HEAD: only your work. Upstream code in there = a conflict resolved backwards.

Push

git push --force-with-lease --force-if-includes origin HEAD   # branch already pushed, then rebased

Both flags: a background fetch (VS Code auto-fetch, an IDE, another agent) refreshes the remote-tracking ref and makes a stale lease look current — --force-if-includes also demands you actually integrated what's on the remote. Rejected → stop and report, never plain --force. Never force-push a shared branch (main, develop, release). Never rebase a branch someone else commits to without asking. Push and open PRs only when asked; the loop itself is local.

Report

Close every sync with one line: commits absorbed, files that conflicted, backup ref — or already up to date when the counter was 0. The user may not read git; the report is how they know what moved.

Never

  • git merge <base> into the feature branch — unless git log --merges --oneline -5 origin/<base> shows the repo really merges. Rebase flattens merge commits inside your branch; that is intended, don't reach for --rebase-merges.
  • git checkout ., git reset --hard, git clean -fd on a dirty tree. Stash instead.
  • git add -A sweeping unrelated files. Stage explicitly.
  • Leave a rebase half-finished across turns. Continue or --abort.

From the file to a first result

The download contains exactly the content displayed on this page. This copy may differ from the latest version in the source repository.

View the source and supporting files

This download contains SKILL.md only. Any scripts, references, templates and dependencies are not included. Get the required files from the source, preserving their directory structure, before continuing.

1. Download the file

Download SKILL.md

From the root of a test project, save the file as .skill-downloads/keep-git-branch-rebased-and-in-sync-mu6guogq/SKILL.md, or use the command below. This folder is for inspecting the skill before installation.

Command for macOS/Linux or WSL: requires a POSIX shell and curl. On Windows without WSL, use the download button and create the folder manually.

mkdir -p '.skill-downloads/keep-git-branch-rebased-and-in-sync-mu6guogq' && curl --fail --show-error --location 'https://skills-guides.com/api/skills/keep-git-branch-rebased-and-in-sync-mu6guogq/download' --output '.skill-downloads/keep-git-branch-rebased-and-in-sync-mu6guogq/SKILL.md.part' && mv '.skill-downloads/keep-git-branch-rebased-and-in-sync-mu6guogq/SKILL.md.part' '.skill-downloads/keep-git-branch-rebased-and-in-sync-mu6guogq/SKILL.md'

2. Check prerequisites

Read SKILL.md before using it. If it references scripts or external services, inspect them and prepare the required access in your test environment.

Tools declared by the author (check availability in your agent): Bash, Read, Edit, Grep, Glob

No recognized prerequisites section in this file. This does not mean it is self-contained: libraries, tools and access requirements may be mentioned elsewhere in the content or source repository.

The platforms on this page are catalog indications. The paths below follow tool documentation; they do not prove this skill has been run in those tools. No minimum tool version is confirmed for this listing.

3. Load the skill

After inspection, copy the complete folder into your project using one of the commands below, then open a new tool session. The command stops if a folder with the same name already exists: compare the files before replacing it.

Claude Code
test -f '.skill-downloads/keep-git-branch-rebased-and-in-sync-mu6guogq/SKILL.md' && test -s '.skill-downloads/keep-git-branch-rebased-and-in-sync-mu6guogq/SKILL.md' && mkdir -p '.claude/skills' && test ! -e '.claude/skills/git-sync' && cp -R '.skill-downloads/keep-git-branch-rebased-and-in-sync-mu6guogq' '.claude/skills/git-sync'

OpenSkills

OpenSkills must already be installed. The local install/read procedure is checked with OpenSkills 1.5.0, which requires Node.js ≥ 20.6.0. Catalog slugs are not resolved automatically.

Official OpenSkills installation
openskills install './.skill-downloads/keep-git-branch-rebased-and-in-sync-mu6guogq'

openskills read 'keep-git-branch-rebased-and-in-sync-mu6guogq'

Reading should display the installed file content and its base directory. It does not run the skill or install its dependencies.

For an agent that reads AGENTS.md, then sync the index. This command changes AGENTS.md: review the diff before using it.

openskills sync

Manual method or another tool: attach SKILL.md to a conversation, or open it in an agent that can read files. Include any required supporting resources. No universal folder is recognized by every tool.

4. Try a first task

Use a short, synthetic input: an API endpoint, a small document or an interface brief. In a new conversation, attach the file or give the agent its path, then adapt this request:

Read .skill-downloads/keep-git-branch-rebased-and-in-sync-mu6guogq/SKILL.md and apply its instructions to this example: [describe a test input]. Identify any missing files, dependencies or access. Produce the result requested by the skill without inventing data or running unreviewed scripts.

Expected result: output matching the skill instructions, or a precise list of missing prerequisites. A read confirmation alone does not validate a first use. If an external resource is unavailable, that path remains untested.

Related skills