Skip to main content

Command referencegh repo clone

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

Linux & WindowsGitHub CLIgitbeginner

What it does

Clone a GitHub repository to your machine using your authenticated gh settings. When people search for gh repo clone, 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.

Clone a GitHub repository to your machine using your authenticated gh settings.

Syntax

gh repo clone <repository> [<directory>] [-- <gitflags>...]

Common options

Flag / optionMeaning
repositoryOWNER/REPO or full GitHub URL.
directoryOptional local folder name.
--Pass extra flags through to git clone.

Practical examples

Clone by name

gh repo clone cli/cli

Clones the GitHub CLI repository into ./cli.

Custom folder

gh repo clone OWNER/REPO my-app

Clones into the my-app directory.

Shallow clone

gh repo clone OWNER/REPO -- --depth 1

Forwards --depth 1 to git clone for a shallow history.

Linux ↔ Windows equivalent

Closest match: git (Linux / bash / sh / zsh). Track source history and collaborate through distributed repositories.

Classic `git clone` works with any remote URL; `gh repo clone` uses GitHub auth/protocol defaults and owner/name shorthand.

Common mistakes

  • Using a private repo name before `gh auth login` succeeds.
  • Forgetting that `--` is required to pass native git clone flags.

FAQ

What does gh repo clone do in GitHub CLI?

Clone a GitHub repository to your machine using your authenticated gh settings.

Does gh repo clone 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 clone example?

Try `gh repo clone cli/cli` — Clones the GitHub CLI repository into ./cli.

Do I need a token in the command line for gh repo clone?

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.