git-upstream-rebase
Skill1 starsChanged 6 months agoMITView on GitHub
Rebase a local branch onto upstream/main and handle conflicts safely. Use when user says \"upstream 更新了\", \"git pull --rebase upstream main\", \"rebase upstream/main\", \"同步上游 main\", \"处理 rebase 冲突\", or wants to update a fork from upstream with automatic conflict resolution.
- Deletes or force-pushes
- Commits and pushes
In this repository4 other files it gives its agents.
- git-fork-remoteSkill
- pixiSkill
- process-recordSkill
- update-project-docsSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
29 rules. About 0 are common, 23 are distinctive, and 6 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈23
Distinctive · estimate
This author's own choices. Worth a look.
6
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- could be automatic: a setting could enforce it
- Distinctive: line 20
Use this skill for requests like:
- Distinctive: line 27
Do not use this skill for merge-based synchronization unless the user explicitly asks for merge commits.
- Distinctive: line 47
Run these checks before changing history:
- Very specific: line 56
If upstream/main is missing or stale, run:
- Distinctive: line 62
Check whether the working tree is clean:
- Distinctive: line 79
Never silently discard user changes.
- Very specific: line 96
Prefer fetch + rebase when you expect conflicts because it gives a clearer recovery path.
- Distinctive: line 100
If rebase stops, inspect:
- Very specific: line 124
Remove conflict markers: <<<<<<<, =======, >>>>>>>.
- Distinctive: line 126
Keep existing file style, ordering, and formatting.
- Distinctive: line 127
Run a targeted validation command when available.
- Distinctive: line 140
If a command opens an editor for a commit message, keep the existing message unless the user asked to edit it.
- Distinctive: line 152
If the project has obvious lightweight checks, run the narrowest relevant one.
- Distinctive: line 160
Do not run expensive full test suites without user approval if they are known to be slow.
- Distinctive: line 164
No rebase is in progress.
- Distinctive: line 175
If the user did not explicitly ask for push, report that push was not run and provide the command only as an optional manual follow-up.
- Distinctive: line 177
If pushing after a rebase, prefer:
- Distinctive: line 183
Use normal push only when the remote branch has not been published before:
- Distinctive: line 193
If the rebase becomes unsafe or the user wants to stop:
- Distinctive: line 199
If a file was resolved incorrectly before staging, restore the conflicted state from the index when possible:
- Distinctive: line 205
If the rebase completed but must be undone, inspect reflog first:
- Distinctive: line 224
If paused for ambiguity, report:
- Distinctive: line 234
Never run git reset --hard, git clean, or destructive checkout commands without explicit user approval.
- Very specific: line 235
Never ask about push or run push unless the user explicitly says push, 推送, or --push.
- Distinctive: line 236
Never use git push --force.
- Very specific: line 237
Never resolve code conflicts by blindly choosing --ours or --theirs across the whole repo.
- Distinctive: line 238
Never delete conflict markers without reviewing the full hunk.
- Distinctive: line 239
Never collect Git credentials or tokens in chat.
- Very specific: line 240
Prefer explicit git fetch upstream && git rebase upstream/main over ambiguous git pull --rebase.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Git Upstream Rebase
Rebase the current work onto an upstream branch, typically upstream/main, and resolve conflicts when it is safe to do so.
This skill is for fork workflows where:
originpoints to the user's fork.upstreampoints to the original repository.- The local branch should replay its commits on top of upstream's latest
main.
When to Use
Use this skill for requests like:
- "上游 main 更新了,帮我 rebase 一下"
- "基于 upstream/main 更新我的 main"
- "git pull --rebase upstream main 可以吗?帮我处理冲突"
- "把我的 fork 同步到 upstream,并自动解决冲突"
Do not use this skill for merge-based synchronization unless the user explicitly asks for merge commits.
Inputs
Default values:
- Local branch: current branch.
- Upstream target:
upstream/main. - Push target: none by default. Only discuss or run push when the user explicitly says
push,推送, or passes--push.
Optional user inputs:
- A different upstream target, such as
upstream/masterorupstream/dev. - A specific local branch to rebase.
- Explicit permission to push after a successful rebase, expressed as
push,推送, or--push.
Procedure
1. Preflight Checks
Run these checks before changing history:
git status --short
git branch --show-current
git remote -v
git rev-parse --verify upstream/mainIf upstream/main is missing or stale, run:
git fetch upstreamCheck whether the working tree is clean:
git diff --stat
git diff --cached --statDecision rules:
| State | Action |
| Clean working tree | Continue |
| Uncommitted user changes exist | Ask whether to commit or stash before rebase |
| Existing rebase in progress | Inspect status; continue, abort, or ask user based on state |
upstream remote missing | Stop and ask to configure upstream first |
| Branch is not the intended branch | Ask before switching branches |
Never silently discard user changes.
2. Start the Rebase
Preferred explicit commands:
git fetch upstream
git rebase upstream/mainEquivalent one-shot command if the user only wants a simple update:
git pull --rebase upstream mainPrefer fetch + rebase when you expect conflicts because it gives a clearer recovery path.
3. Detect Conflict Type
If rebase stops, inspect:
git status --short
git diff --name-only --diff-filter=U
git diff --checkClassify conflicts:
| Conflict Type | Auto-resolution Policy |
| Add/add in docs, examples, catalog tables | Attempt manual merge preserving both sides |
| Same-line Markdown prose conflict | Attempt semantic merge only if both edits are clearly compatible |
| Generated files, lockfiles, snapshots | Prefer regenerating from source if the repo has a known command; otherwise ask |
| Code logic conflict | Resolve only if behavior is obvious and tests can verify it; otherwise ask |
| Delete/modify conflict | Ask unless the deleted file is clearly generated or obsolete |
| Binary conflict | Ask; do not guess |
4. Automatic Conflict Resolution Loop
For each conflicted file:
- Open the conflict hunks.
- Remove conflict markers:
<<<<<<<,=======,>>>>>>>. - Preserve upstream changes and local changes when compatible.
- Keep existing file style, ordering, and formatting.
- Run a targeted validation command when available.
- Stage only the resolved files.
Useful commands:
git diff -- <file>
git add <file>
git rebase --continueRepeat until the rebase completes or a conflict is ambiguous.
If a command opens an editor for a commit message, keep the existing message unless the user asked to edit it.
5. Validate After Rebase
Always run:
git status --short
git log --oneline --decorate --max-count=8
git diff --checkIf the project has obvious lightweight checks, run the narrowest relevant one. Examples:
npm test -- --runInBand
pytest
make testDo not run expensive full test suites without user approval if they are known to be slow.
Completion criteria:
- No rebase is in progress.
git status --shorthas no unexpected changes.HEADis based on the requested upstream target.- Conflict markers are absent from resolved files.
git diff --checkpasses.- Targeted tests or format checks pass when available.
6. Push Only When Explicitly Requested
A rebase rewrites local commit hashes. Do not ask about push, suggest push as the next action, or run push unless the user explicitly includes push, 推送, or --push in the request.
If the user did not explicitly ask for push, report that push was not run and provide the command only as an optional manual follow-up.
If pushing after a rebase, prefer:
git push --force-with-lease origin <branch>Use normal push only when the remote branch has not been published before:
git push -u origin <branch>Explain that --force-with-lease is safer than --force because it refuses to overwrite remote work that appeared after the last fetch.
Recovery Commands
If the rebase becomes unsafe or the user wants to stop:
git rebase --abortIf a file was resolved incorrectly before staging, restore the conflicted state from the index when possible:
git checkout --conflict=merge -- <file>If the rebase completed but must be undone, inspect reflog first:
git reflog --date=local --max-count=20Then ask before resetting to an earlier commit.
Reporting Format
When finished, report:
Rebased <branch> onto <upstream-target>.
Conflicts resolved: <count/files or none>.
Validation: <commands and pass/fail>.
Push: not run / pushed to origin with --force-with-lease.If paused for ambiguity, report:
Rebase paused at <file>.
Reason: <why automatic resolution is unsafe>.
Options: keep upstream / keep local / manually combine / abort rebase.Safety Rules
- Never run
git reset --hard,git clean, or destructive checkout commands without explicit user approval. - Never ask about push or run push unless the user explicitly says
push,推送, or--push. - Never use
git push --force; usegit push --force-with-leaseonly after explicit push permission. - Never resolve code conflicts by blindly choosing
--oursor--theirsacross the whole repo. - Never delete conflict markers without reviewing the full hunk.
- Never collect Git credentials or tokens in chat; ask the user to type secrets directly into the terminal.
- Prefer explicit
git fetch upstream && git rebase upstream/mainover ambiguousgit pull --rebase.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

