gh repo clone Command Reference
Clone a repository using your GitHub CLI authentication.
gh repo clone clones a repo using the credentials gh already holds, which makes cloning private repos from scripts straightforward.
What it does
gh repo clone clones OWNER/REPO (or a URL) into a local directory using gh authentication, and configures the upstream remote for forks. Flags after a -- separator are passed straight through to git clone.
Common flags and usage
- OWNER/REPO [directory]: repository and optional target directory
- -- <git flags>: pass options like --depth 1 to git clone
- Authenticated via gh, so private repos clone without extra token setup
Example
shell
- name: Clone a private dependency
env:
GH_TOKEN: ${{ secrets.CLONE_PAT }}
run: gh repo clone my-org/internal-lib -- --depth 1In CI
For an extra private repo beyond the one actions/checkout already pulled, gh repo clone with a GH_TOKEN that has access avoids hand-rolling an authenticated git URL. Pass --depth 1 after -- for shallow clones.
Key takeaways
- gh repo clone uses gh auth, so private repos clone with no URL token plumbing.
- Flags after -- pass straight through to git clone (for example --depth 1).
- Useful for pulling an extra private repo alongside actions/checkout.
Related guides
gh auth login Command ReferenceReference for gh auth login in CI/CD: authenticate the GitHub CLI non-interactively with a token via stdin or…
gh api Command ReferenceReference for gh api in CI/CD: call any REST or GraphQL endpoint with authentication handled, pass fields, pa…
gh secret set Command ReferenceReference for gh secret set in CI/CD: create or update Actions, environment, or Dependabot secrets non-intera…