Command referencegh repo sync
gh repo sync command (Linux & Windows / GitHub CLI)
What it does
Sync the local repository or a fork branch with its upstream default branch. When people search for gh repo sync, they usually want practical GitHub CLI flags, safe examples, and how this subcommand fits everyday PR and repo workflows on Linux, Windows, and macOS. Syntax, options, and copyable examples are below.
Sync the local repository or a fork branch with its upstream default branch.
Syntax
gh repo sync [<destination-repository>] [flags]
Common options
| Flag / option | Meaning |
|---|---|
| -b, --branch | Branch to sync (defaults to the default branch). |
| --source | Upstream source repository when syncing a fork. |
| --force | Hard-reset the destination branch to match source (destructive). |
Practical examples
Sync current fork
gh repo sync
Updates the local default branch from upstream when configured.
Sync a branch
gh repo sync --branch main
Explicitly syncs the main branch.
Force align
gh repo sync --force
Resets the destination to match upstream — discards divergent commits.
Common mistakes
- Using `--force` on a branch with unpushed work you still need.
- Running sync before setting the upstream remote on a fresh fork.
Related commands
- gh repo forkFork a GitHub repository to your account and optionally clone the fork locally.
- gh pr createCreate a pull request from the current branch with title, body, reviewers, and base branch options.
- gh repo cloneClone a GitHub repository to your machine using your authenticated gh settings.
- gh auth loginAuthenticate the GitHub CLI with GitHub.com or GitHub Enterprise so other gh commands can run.
- gh pr mergeMerge a pull request using merge commit, squash, or rebase strategies.
- gitTrack source history and collaborate through distributed repositories.
- gh pr checkoutCheck out a pull request locally as a branch so you can build, test, or review the changes.
- gh pr listList pull requests in a repository with state, author, and search filters.
FAQ
What does gh repo sync do in GitHub CLI?
Sync the local repository or a fork branch with its upstream default branch.
Does gh repo sync work on Windows and Linux?
Yes. The GitHub CLI (`gh`) runs on Linux, Windows, and macOS with the same subcommand syntax after you authenticate with `gh auth login`.
What is a practical gh repo sync example?
Try `gh repo sync` — Updates the local default branch from upstream when configured.
Do I need a token in the command line for gh repo sync?
Prefer `gh auth login` so credentials stay in the system keyring or secure storage. Avoid pasting personal access tokens into shell history.
Browse the full Linux and Windows command reference to search more bash, CMD, PowerShell, Conda, and GitHub CLI commands.