Skip to content
Latchkey

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 1

In 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

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →