Skip to main content

Command referencegh repo sync

gh repo sync command (Linux & Windows / GitHub CLI)

Linux & WindowsGitHub CLIgitintermediateDestructive — use carefully

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 / optionMeaning
-b, --branchBranch to sync (defaults to the default branch).
--sourceUpstream source repository when syncing a fork.
--forceHard-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.

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.