Command referencegh repo clone
gh repo clone command (Linux & Windows / GitHub CLI)
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 / option | Meaning |
|---|---|
| repository | OWNER/REPO or full GitHub URL. |
| directory | Optional 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.
Related commands
- gh repo createCreate a new GitHub repository from the current directory or as an empty remote repo.
- gh repo forkFork a GitHub repository to your account and optionally clone the fork locally.
- gh auth loginAuthenticate the GitHub CLI with GitHub.com or GitHub Enterprise so other gh commands can run.
- gh repo viewDisplay metadata about a GitHub repository in the terminal or open it in a browser.
- gh pr createCreate a pull request from the current branch with title, body, reviewers, and base branch options.
- 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.
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.