What this error means
Git tried to contact the remote (origin) but could not authenticate, reach it, or find the repository. The most common causes are:
- Wrong remote URL (typo, protocol mismatch)
- Missing or unusable SSH key
- Insufficient permissions on the remote
- HTTPS credentials rejected (need a token)
- Network, proxy, or host key verification issues
Quickstart (fast checklist)
- Verify the remote:
git remote -v - Test connectivity:
- SSH:
ssh -T [email protected](or your host) - HTTPS:
git ls-remote https://github.com/example/acme.git
- SSH:
- Fix the URL:
git remote set-url origin <correct-url> - SSH: load key and try again:
ssh-add -l || ssh-add ~/.ssh/id_ed25519 - HTTPS: use a Personal Access Token instead of a password
- If CI/CD: ensure the key/secret and known_hosts are present
Minimal working example (local bare remote)
Use a local bare repo as a remote to confirm Git works end-to-end on your machine.
set -euo pipefail
# 1) Create a bare "remote"
rm -rf /tmp/git-remote-demo
mkdir -p /tmp/git-remote-demo
git init --bare /tmp/git-remote-demo/remote.git
# 2) Create a repo and push to the local remote
rm -rf /tmp/git-wrk && mkdir -p /tmp/git-wrk && cd /tmp/git-wrk
git init
printf "hello\n" > README.md
git add README.md
git commit -m "init"
git checkout -b main
git remote add origin /tmp/git-remote-demo/remote.git
git push -u origin main
# Success here proves your Git install and basic permissions are fine.
If this works but your real remote fails, the issue is with remote URL, auth, or network.
Step-by-step fix
- Confirm the remote URL
git remote -v
# If wrong, set it:
# SSH example
git remote set-url origin [email protected]:example/acme.git
# HTTPS example
git remote set-url origin https://github.com/example/acme.git
- Check repository existence and your access
- Ensure the project exists on the server and your account or deploy key has read/write rights.
- If you see “Repository not found”, verify org/team membership and repo visibility.
- SSH authentication (common case)
# List loaded keys
ssh-add -l || eval "$(ssh-agent -s)" && ssh-add ~/.ssh/id_ed25519
# Test host auth (replace host as needed)
ssh -T [email protected]
# If the wrong key is chosen, create an SSH config:
# ~/.ssh/config
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519
IdentitiesOnly yes
# Fix key permissions if needed
chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_ed25519 ~/.ssh/id_rsa 2>/dev/null || true
# If host key changed or missing
ssh-keygen -R github.com
ssh -o StrictHostKeyChecking=accept-new [email protected] || true
# Increase SSH verbosity when testing Git
GIT_SSH_COMMAND='ssh -v' git ls-remote origin
- HTTPS authentication
- Many providers require a Personal Access Token (PAT) instead of a password.
- When prompted for password, paste the PAT.
# Update to HTTPS if preferred
git remote set-url origin https://github.com/example/acme.git
# Clear bad cached creds and retry to prompt for new creds
git credential reject <<<'protocol=https\nhost=github.com\n'
# Optional: cache credentials for this session
git config --global credential.helper cache
- Proxies, firewalls, and corporate networks
# Inspect proxy settings
env | grep -i proxy || true
git config --global --get http.proxy || true
# Temporarily disable for test
unset http_proxy https_proxy no_proxy
GIT_SSH_COMMAND='ssh -o ConnectTimeout=10' git ls-remote origin
- If SSH is blocked outbound, switch to HTTPS.
- If HTTPS is intercepted, install the corporate CA certificate and configure Git/cURL to trust it.
- CI/CD runners (DevOps)
- Provide the private key via secret variables; add known_hosts for the Git host.
- Use a deploy key or a bot user with the least privileges required.
- Non-interactive environments need ssh-agent and key loading commands in the job.
- Submodules
- Each submodule has its own remote. Run
git submodule foreach 'git remote -v'and fix URLs and auth per submodule.
- Retry the operation
git fetch --prune
git push -u origin HEAD
Error-to-cause quick map
| Symptom snippet | Likely cause | First fix |
|---|---|---|
| Permission denied (publickey) | SSH key not offered/authorized | Load key, add to account, fix ~/.ssh/config |
| Repository not found | URL typo or no access | Correct URL, confirm rights |
| Could not resolve hostname | DNS/proxy | Check network, set HTTPS or fix DNS |
| Connection timed out | Firewall/proxy | Switch protocol, open port 22/443, set proxy |
| Host key verification failed | Host key changed/missing | Update known_hosts safely |
Pitfalls to avoid
- Mixing multiple SSH keys without an SSH config; the wrong key gets used.
- Using deprecated keys (DSA, weak RSA) blocked by providers; prefer ed25519.
- Wrong protocol for policy (company enforces HTTPS-only or SSH-only).
- CI jobs missing known_hosts, causing strict host checks to fail.
- Windows: ensure you use the same SSH (Git Bash vs Windows OpenSSH) consistently, or specify core.sshCommand.
Performance notes
- Prefer SSH multiplexing to speed repeated operations:
# ~/.ssh/config
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519
ControlMaster auto
ControlPersist 5m
ControlPath ~/.ssh/cm-%r@%h:%p
- Use shallow and partial clones for large repos:
git clone --depth 1 --filter=blob:none [email protected]:example/acme.git
- Parallelize fetches:
git -c fetch.parallel=4 fetch --all --prune
- Reduce SSH/TLS handshake cost in CI by reusing the workspace or enabling caching between steps.
FAQ
Why does SSH fail but HTTPS works?
- Likely port 22 blocked or SSH key not available. Use HTTPS or provide the key.
Do I need a PAT for HTTPS?
- Yes on most providers if passwords are disabled. Generate a token with the needed scopes.
It works locally but fails in CI—why?
- Missing key/known_hosts or different URL. Add ssh-agent steps and known_hosts to the pipeline.
Can I safely delete known_hosts?
- Do not delete the whole file. Remove only the stale host entry with
ssh-keygen -R hostand re-add.
- Do not delete the whole file. Remove only the stale host entry with