Skip to content
Latchkey

Composer: Failed to Clone - Git Authentication Failed in CI

Composer falls back to cloning a package from its Git source when no dist archive is available or for dev- branches. In CI, a private clone fails with "Authentication failed" because the runner has no Git credentials for the host.

What this error means

Composer prints "Failed to clone ... via https/ssh protocols, aborting" with "fatal: Authentication failed for 'https://...'". The same install works locally where Git credentials or an SSH key exist.

composer
  - Syncing acme/internal (dev-main) into cache
Failed to clone https://github.com/acme/internal.git, try running with
'--verbose' to debug.
fatal: Authentication failed for 'https://github.com/acme/internal.git/'

Common causes

No Git credentials for the private host in CI

The runner has no token or SSH key for the host, so the clone cannot authenticate and Composer cannot prompt non-interactively.

A dev/source install forces a clone

dev- constraints or --prefer-source make Composer clone instead of downloading a dist zip, requiring Git auth it does not otherwise need.

How to fix it

Provide an OAuth token for HTTPS clones

Configure a token Composer uses for the host before installing.

composer
composer config --global --auth github-oauth.github.com "\$GH_TOKEN"
composer install --no-interaction

Use an SSH deploy key and ssh URLs

composer
eval "\$(ssh-agent -s)"
ssh-add - <<< "\$DEPLOY_KEY"
# composer.json
# "repositories": [{ "type": "vcs", "url": "git@github.com:acme/internal.git" }]

Prefer dist to avoid clones where possible

  1. Use --prefer-dist so Composer downloads archives instead of cloning.
  2. Verify access with git ls-remote using the same credential.
  3. Confirm the credential host matches the repository URL scheme.

How to prevent it

  • Inject a least-privilege token or deploy key into CI for private Git sources.
  • Prefer --prefer-dist so most installs need no Git auth.
  • Match the repository URL scheme (https vs ssh) to the credential provided.

Frequently asked questions

What causes ""Failed to clone" (git auth)"?
The runner has no token or SSH key for the host, so the clone cannot authenticate and Composer cannot prompt non-interactively.
How do I fix "Failed to clone" (git auth)?
Configure a token Composer uses for the host before installing.

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card