A gh CLI extension that keeps local branches in sync with a remote. It fetches, fast-forwards outdated branches, warns about unpushed work, and cleans up branches whose upstream was deleted after merging (including squash merges).
This was built to replace the sync command from the deprecated hub tool.
gh extension install wassimk/gh-syncRun inside any git repository:
gh syncThat's it. The command will:
- Find the primary remote (
upstream>github>origin) - Fetch with pruning
- For each local branch:
- Fast-forward if the branch is behind its remote counterpart
- Warn if the branch has unpushed commits
- Delete if the upstream was removed and the branch was merged (or squash-merged) into the default branch
- Warn if the upstream was removed but the branch appears unmerged
Branches without explicit tracking configuration are matched by name against the remote.
--verbose, -v Log each git command to stderr
Fast-forward a branch that fell behind:
Updated branch feature-login (was 3a1b2c4).
Warn about local work that hasn't been pushed:
warning: 'experiment' seems to contain unpushed commits
Clean up a merged branch whose remote was deleted:
Deleted branch add-user-api (was 7f8e9d0).
gh extension upgrade wassimk/gh-sync
gh extension remove gh-syncInspired by jacobwgillespie/git-sync, rebuilt as a gh CLI extension.