Sync submodules

From different-ai/the-factory · View interactive version

Sync submodules is an AI agent skill from the GitHub repository different-ai/the-factory. Safely sync/pull the superproject and update git submodules, including handling dirty submodules (e.g. a modified Cargo.lock) via stash. Triggers when user mentions: - "sync submodules" - "submodule update failed" - "local changes would be overwritten by checkout" - "not our ref

How to use this skill

Skill file

Quick Usage (Already Configured)

1) See what is dirty (root + submodules)

date
git status --porcelain
git submodule foreach --recursive 'echo "--- $name ($path)"; git status --porcelain'

2) If a submodule is dirty, stash inside that submodule

Example for _repos/openwork when Cargo.lock blocks an update:

git -C _repos/openwork status --porcelain
git -C _repos/openwork stash push -u -m "wip: allow submodule update"

Notes:

3) Pull root + update submodules to the commits pinned by the root repo

git pull
git submodule sync --recursive
git submodule update --init --recursive
date

4) Re-apply the stash (optional)

Only do this if you actually want your local submodule changes back.

git -C _repos/openwork stash list
git -C _repos/openwork stash pop

Common Gotchas

git submodule update --remote --recursive
git status

Submodule Pin Is Unreachable ("not our ref")

Symptom:

Meaning:

Fix (safe, local):

  1. Pull root without touching submodules:
git pull --recurse-submodules=no
  1. Move the submodule to a reachable ref (example uses origin/dev):
git -C _repos/<name> fetch origin --prune
git -C _repos/<name> checkout dev
git -C _repos/<name> pull --ff-only origin dev
  1. Stage the gitlink in the root repo:
git add _repos/<name>
git status

Fix (proper, shared):

One-Liner Helper (Conservative)

This prints dirty submodules without changing anything:

git submodule foreach --recursive 'test -z "$(git status --porcelain)" || echo "DIRTY: $name ($path)"'
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.