repo-sync-deleted-remote-branch-and-unrelated-history-recovery
Recover multi-repo sync failures caused by deleted upstream branches, stale git index locks, and local branches with unrelated history to the remote default branch.
Best use case
repo-sync-deleted-remote-branch-and-unrelated-history-recovery is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Recover multi-repo sync failures caused by deleted upstream branches, stale git index locks, and local branches with unrelated history to the remote default branch.
Teams using repo-sync-deleted-remote-branch-and-unrelated-history-recovery should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/repo-sync-deleted-remote-branch-and-unrelated-history-recovery/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How repo-sync-deleted-remote-branch-and-unrelated-history-recovery Compares
| Feature / Agent | repo-sync-deleted-remote-branch-and-unrelated-history-recovery | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Recover multi-repo sync failures caused by deleted upstream branches, stale git index locks, and local branches with unrelated history to the remote default branch.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# Repo Sync: Deleted Remote Branch + Unrelated History Recovery
Use this when `./scripts/repository_sync pull all` or equivalent multi-repo sync fails and the failing repos are not simply dirty/diverged. This pattern covers three recurring failure modes seen in workspace-hub subrepos:
1. local branch tracks a remote branch that was deleted
2. a stale `.git/index.lock` blocks checkout/pull
3. local branch history is unrelated to the remote default branch, so `git pull` fails with `refusing to merge unrelated histories`
## Symptoms
### Deleted tracked branch
`git pull` shows:
```text
Your configuration specifies to merge with the ref 'refs/heads/<branch>'
from the remote, but no such ref was fetched.
```
### Stale lock
```text
fatal: Unable to create '.git/index.lock': File exists.
```
### Unrelated histories
```text
fatal: refusing to merge unrelated histories
```
## Workflow
### 1. Diagnose the failing repo precisely
For each failed repo:
```bash
git branch --show-current
git rev-parse --abbrev-ref --symbolic-full-name @{u} 2>/dev/null || echo none
git status --short
git remote -v
git fetch --prune origin
```
Also inspect remote default branch if needed:
```bash
git remote show origin | sed -n '/HEAD branch/s/.*: //p'
git branch -r
```
### 2. If the tracked remote branch was deleted
Do not keep retrying `git pull` on the stale branch.
Recovery:
```bash
git fetch --prune origin
git checkout <default-branch>
git branch --set-upstream-to=origin/<default-branch> <default-branch>
git pull --no-rebase origin <default-branch>
```
Notes:
- In the observed case, `chore/gitignore-Codex-worktrees` had been deleted remotely in multiple repos.
- `main` already existed locally and was the correct recovery target.
- After `fetch --prune`, the stale remote-tracking branch disappeared and normal pull succeeded.
### 3. If a stale `.git/index.lock` blocks the fix
Before removing the lock, verify no active git process is operating in that repo.
```bash
ps -ef | grep '[g]it'
```
If the lock is stale, remove it and retry:
```bash
rm .git/index.lock
git fetch --prune origin
git checkout <default-branch>
git branch --set-upstream-to=origin/<default-branch> <default-branch>
git pull --no-rebase origin <default-branch>
```
### 4. If local branch has unrelated history to remote default branch
Do not merge unrelated histories during sync. Preserve local work first, then align to the remote default branch cleanly.
Recovery:
```bash
git fetch --prune origin
git branch preserve/pre-sync-$(date +%Y%m%d) <local-branch>
git checkout -B <remote-default-branch> origin/<remote-default-branch>
git branch --set-upstream-to=origin/<remote-default-branch> <remote-default-branch>
git pull --no-rebase origin <remote-default-branch>
```
Notes:
- This preserves the old local history for later review instead of destroying it.
- In the observed case, local `main` was unrelated to `origin/master`, so the safe fix was:
- preserve local `main`
- switch to a clean local `master` tracking `origin/master`
- Do not use `--allow-unrelated-histories` for repo hygiene sync.
### 5. Re-verify repo and ecosystem state
Per repo:
```bash
git status --short --branch
```
Across workspace:
```bash
./scripts/repository_sync status all
```
Success means each repo reports:
- correct tracked branch
- no local changes
- up to date with remote
## Important caveat: root workspace-hub may still be dirty while subrepos are clean
`repository_sync status all` reflects the subrepos it manages. It can report all repos clean/up to date while the workspace-hub root repo is still changing due to active review/background processes.
So after syncing subrepos, separately check the root repo:
```bash
git -C /mnt/local-analysis/workspace-hub status --short --branch
ps -ef | grep -E '[c]odex|[g]emini|[c]laude'
```
If active processes are still writing artifacts, root cleanliness is not stable yet. Commit only what is appropriate, and expect additional follow-up commits until those processes finish.
## Do not
- do not force-push
- do not merge unrelated histories just to make pull succeed
- do not delete old local history without preserving it on a backup branch
- do not remove `.git/index.lock` without first checking for active git processes
- do not declare the whole workspace clean based only on subrepo status if the root repo is still being mutated by running jobsRelated Skills
interactive-report-generator
Generate interactive HTML reports with Plotly visualizations from data analysis results. Supports dashboards, charts, and professional styling.
data-validation-reporter
Generate interactive validation reports with quality scoring, missing data analysis, and type checking. Combines Pandas validation, Plotly visualization, and YAML configuration for comprehensive data quality reporting.
repo-ecosystem-hygiene
Interpret the daily read-only repo ecosystem hygiene audit and route remediation through approved workflows.
orcaflex-reporting-fixture-proof-pattern
Build and extend fixture-backed OrcaFlex reporting proof paths in digitalmodel using stable metadata baselines, normalized HTML snapshots, and reusable reporting test helpers.
worktree-branch-sync-hygiene
Class-level branch, worktree, dirty-main, stash, sync, and hook hygiene for workspace-hub style multi-repo work.
repo-sync
Smart repository synchronization across workspace-hub ecosystem — diagnoses and fixes pull failures (detached HEAD, diverged branches, uncommitted changes)
repo-structure
Canonical source layout, test mirroring, root cleanliness, gitignore, docs classification, and committed artifact rules for all workspace-hub tier-1 repos. Consult before creating directories or files in any submodule.
repo-portfolio-steering
Generate a one-page portfolio steering report for workspace-hub. Use when the user invokes /repo-portfolio-steering, asks about harness vs engineering balance, wants a portfolio health check, or asks which repos to fund next. Reports on portfolio steering, GTM readiness, and provider activity balance.
repo-mission-portfolio-audit
Audit the workspace-hub repo portfolio to extract each repo's mission, identify documentation gaps, and prioritize a plan/approval sequence with explicit LLM-wiki weighting for future issue triage.
remote-desktop
Connect to dev-secondary graphical desktop from dev-primary via VNC over SSH tunnel
mixed-ops-vs-repo-fix-plan-boundary
Plan mixed operational-vs-repo remediation issues by proving live-state classification first, then only proposing code changes for confirmed repo-owned failure paths.
repo-separation-for-sensitive-data
Architecture pattern for splitting confidential data and reusable algorithms across repos