GitHub Sync
Overview
Use scripts/sync-repo.sh instead of rewriting ad-hoc git fetch and git pull logic. The script resolves the sync target, creates a local tracking branch when needed, and only performs fast-forward updates.
Workflow
- Check whether the user wants the remote default branch, a specific branch, or the current branch.
- Prefer
originunless the user explicitly asks for another remote. - Run the bundled script:
scripts/sync-repo.sh
scripts/sync-repo.sh --branch main
scripts/sync-repo.sh --current
- If the script reports that a branch switch would be unsafe because the worktree is dirty, stop and ask the user instead of stashing, resetting, or forcing the switch.
- After a successful sync, use
git status -sbwhen the user wants explicit verification.
Branch Selection
- No flags: sync the remote default branch from
origin/HEAD. --branch <name>: sync that branch fromorigin/<name>.--current: sync the currently checked out branch without switching away first.
Hard Rules
- Never auto-stash, reset, rebase, or create a merge commit as part of sync.
- Use fast-forward-only updates.
- Never delete local branches or remote branches as part of sync.
- If
origin/HEADis unavailable and no explicit branch was provided, stop and ask which branch to sync. - If the requested remote branch does not exist, stop and report the missing branch clearly.
- For branch-creation workflows that must branch from updated
main, runscripts/sync-repo.sh --branch mainfirst.
Script
scripts/sync-repo.sh: fetches fromorigin, resolves the target branch, creates a local tracking branch when needed, and fast-forwards it safely.