Sync the current git repository or local child git repositories to same-name
GitHub repositories, and batch delete remote repositories by gh repo list
filters.
cd /path/to/parent-folder
npx github-synccd /path/to/single-repo
npx github-syncnpx github-sync delete-remote --fork --language JavaScriptnpx github-sync delete-remote --fork --language JavaScript --dry-rungithub-sync [--include NAME] [--exclude NAME]
github-sync delete-remote [--fork] [--language LANGUAGE] [--include NAME] [--exclude NAME] [--dry-run] [--yes]-i, --include NAME: only sync a direct child directory by name. Repeatable.-e, --exclude NAME: skip a direct child directory by name. Repeatable.delete-remote --fork: delete only fork repositories owned by the target owner.delete-remote -l, --language LANGUAGE: delete only repositories whose primary language matchesLANGUAGE.delete-remote -i, --include NAME: only delete a repository by name. Repeatable.delete-remote -e, --exclude NAME: skip a repository by name. Repeatable.delete-remote --dry-run: print matched repositories without deleting them.delete-remote --yes: pass--yesto eachgh repo deletecall.
delete-remote requires at least one filter, either --fork or --language, so
an unfiltered owner-wide delete cannot run by accident.
Sync --include and --exclude apply only in child-repository mode. If the
current directory is itself an independent git repository, github-sync syncs
the current repository. In delete-remote mode, --include and --exclude
filter matched remote repositories by repository name.
gh already provides the primitives: gh repo list can filter repositories,
and gh repo delete can delete one repository. github-sync combines those
steps into a safer batch workflow:
- Uses
gh repo listwith the supported filters, currently--forkand--language. - Supports repeated
--includeand--excludename filters on top of thegh repo listresult. - Prints the exact matched repository list before deletion starts.
- Supports
--dry-runto audit the matched list without deleting anything. - Deletes every matched repository by calling
gh repo deletefor each one. - Refuses to run remote deletion without a filter.
- Uses the active
ghaccount as the GitHub owner for sync and cleanup.
This is useful when cleaning generated forks, experiments, or language-specific
scratch repositories where deleting one repo at a time through gh is tedious.
For syncing, github-sync also wraps the common local workflow around gh:
- Uses
gh repo create --source --remotewhen a matching GitHub repository does not exist yet. - Uses
gh repo view --json urlto resolve the HTTPS remote URL instead of constructing GitHub URLs manually or using SSH. - Uses
gh repo syncfor remote-to-local fast-forwards when branch names match. - Keeps
gitonly for local repository operations thatgh repodoes not replace: checking the worktree, committing local changes, comparing branch ancestry, pushing local commits, and applying local fast-forwards.
When the current directory is an independent git repository, github-sync:
- Commits local changes so the worktree is clean.
- Ensures a same-name GitHub repository exists.
- Adds or updates the configured remote for the current repository.
- Syncs local and remote when one side can fast-forward the other.
- Skips syncing if local and remote histories diverge.
When the current directory is not an independent git repository, github-sync
checks each direct child directory:
- Skips the child if it is not an independent git repository.
- Commits local changes so the worktree is clean.
- Ensures a same-name GitHub repository exists.
- Uses
gh repo syncfor remote-to-local fast-forwards when local and remote branch names match. - Falls back to
gitfor branch creation, local-to-remote pushes, branch-name mismatches, or whengh repo synccannot complete the sync. - Skips that child directory if local and remote histories diverge.
Prerequisites: git, gh, find, realpath, and sort.