Skip to content

gh repo clone of a public repository is unauthenticated, so it is throttled by GitHub's anonymous-download limit #14329

Closed as not planned

Description

@konard

Summary

gh repo clone <public-repo> performs the clone anonymously even when gh holds a valid token. Because GitHub throttles unauthenticated git downloads, an authenticated user can be refused with:

fatal: remote error: GitHub is temporarily limiting some unauthenticated downloads to protect the stability of the platform. Please retry later or authenticate.
failed to run git: exit status 128

…while every gh api call from the same machine, in the same second, succeeds.

The cause is that gh auth setup-git installs a credential helper:

credential.https://github.com.helper = !gh auth git-credential

and git only consults a credential helper after the server answers 401. github.com answers 200 for a public repository, so git never asks the helper and never sends an Authorization header. gh repo clone shells out to that git clone, so it inherits the behaviour.

gh version

gh version 2.95.0 (2026-06-17)
git version 2.43.0

Reproducible example

gh auth status          # logged in
gh auth setup-git       # credential helper installed

# Count the Authorization headers git actually sends:
GIT_TRACE_CURL=/tmp/trace.log GIT_TRACE_CURL_NO_DATA=1 \
  gh repo clone cli/cli /tmp/clone-a -- --depth 1
grep -ci 'Send header: Authorization:' /tmp/trace.log
# -> 0

# Same clone with the token sent preemptively:
GIT_TRACE_CURL=/tmp/trace2.log GIT_TRACE_CURL_NO_DATA=1 \
GIT_CONFIG_COUNT=1 \
GIT_CONFIG_KEY_0='http.https://github.com/.extraheader' \
GIT_CONFIG_VALUE_0="Authorization: Basic $(printf 'x-access-token:%s' "$(gh auth token)" | base64 -w0)" \
  gh repo clone cli/cli /tmp/clone-b -- --depth 1
grep -ci 'Send header: Authorization:' /tmp/trace2.log
# -> 3

(A scripted version of this measurement: https://github.com/link-assistant/hive-mind/blob/main/experiments/issue-2192-anonymous-clone-auth.mjs)

Expected vs actual

  • Expected: when gh is authenticated, gh repo clone sends the token, so the clone counts against the authenticated budget.
  • Actual: the clone is anonymous for public repositories, and is throttled as such. The failure text ("Please retry later or authenticate") is confusing, because the user is authenticated — gh auth status is green and gh api works.

Workaround

Send the token preemptively — the same mechanism actions/checkout uses — through environment variables so it never lands in a config file or in argv:

export GIT_CONFIG_COUNT=1
export GIT_CONFIG_KEY_0='http.https://github.com/.extraheader'
export GIT_CONFIG_VALUE_0="Authorization: Basic $(printf 'x-access-token:%s' "$(gh auth token)" | base64 -w0)"
gh repo clone owner/repo

Suggested fix

In the clone path (pkg/cmd/repo/clone), when a token for the host is available, pass the preemptive header to the git invocation, e.g. append

-c http.https://<host>/.extraheader=Authorization: Basic <base64("x-access-token:"+token)>

or set the equivalent GIT_CONFIG_COUNT/GIT_CONFIG_KEY_n/GIT_CONFIG_VALUE_n variables on the child process (the env form keeps the token out of ps output, which is why we prefer it downstream). Behaviour for private repositories is unchanged — those already get a 401 and reach the helper.

Related downstream report and analysis: link-assistant/hive-mind#2192

Activity

  1. added
    needs-triage
    on Sep 3, 2026
  2. cli-triage commented on Sep 3, 2026

    @cli-triage

    Thanks for the detailed report and reproduction. Tracing this through the source: gh repo clone (https://github.com/cli/cli/blob/9646a83d34f4e4968d76bed989f9f4e25fd78a7a/pkg/cmd/repo/clone/clone.go#L184-L189) calls gitClient.Clone (https://github.com/cli/cli/blob/9646a83d34f4e4968d76bed989f9f4e25fd78a7a/git/client.go#L922-L940), which just execs git clone with the constructed URL and passed-through args — no Authorization header or extraheader config is injected. Since gh auth setup-git only installs a credential helper (invoked by git after a 401), and github.com returns 200 for public repos, the token never gets sent, matching the reported behavior. This looks like a legitimate bug, not just expected credential-helper semantics, since gh already holds a token it could use preemptively (as actions/checkout does). No exact duplicate found (searched cli/cli issues); related but distinct: #12591, #13032, #13307, #12891, #13317. Suggesting bug, priority-3 (workaround exists, public-repo-only, no data loss/security impact), and gh-repo.

    Generated by Issue Triage (skills-driven) for #14329 · copilot · auto · 29.9 AIC · ⌖ 1.43 AIC · ⊞ 11K · ◷

  3. added
    bug
    priority-3
    gh-repo
    on Sep 3, 2026
  4. removed
    needs-triage
    on Sep 3, 2026
  5. williammartin commented on Sep 4, 2026

    @williammartin
    Member

    Hey @konard,

    As per https://github.com/orgs/community/discussions/206581#discussioncomment-18251638, the abuse team have been rolling out some protections. I think you landed in a window here where the platform was returning 200 plus an error, and it has later been correctly updated to 401. Hopefully you shouldn't see this again, at least when authenticated via gh in the setup you have.

    Sorry for the inconvenience and thanks for the detailed write up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    buggh-repopriority-3

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions