| name | git-https-push-with-token |
| description | Git push to HTTPS remote using token authentication — avoids SSH setup, works in CI/automated environments. |
| triggers | ["git push fails with \"authentication failed\"","HTTPS token embedded in URL but push still asks for credentials","git credential.helper interfering with URL-embedded auth"] |
Git HTTPS Push with Token Authentication
The Problem
Git push to an HTTPS remote fails even when the token is embedded in the URL:
remote: authentication failed
fatal: Authentication failed for 'https://github.com/user/repo.git'
Key Insight (Gotcha)
Setting credential.helper overrides URL-embedded credentials.
Git's credential helper runs before the URL-embedded token is used. If credential.helper is configured, git uses that instead of the token in the URL.
Correct Approach
git remote set-url origin "https://github.com/USER/REPO.git"
git remote set-url origin "https://GITHUB_TOKEN@github.com/USER/REPO.git"
git config --unset credential.helper
git push origin main
Alternative: Store credentials persistently
git config credential.helper "store --file ~/.git-credentials"
echo "https://GITHUB_TOKEN@github.com" > ~/.git-credentials
chmod 600 ~/.git-credentials
git push origin main
Checklist When Push Asks for Password
Debug
git remote -v
git config --list --show-origin | grep credential
GIT_TRACE=1 git push origin main 2>&1 | grep -i credential