Stop Git asking for your username and password every time
How do I make Git remember my credentials?
Short answer
Configure a credential helper that stores the token in your OS keychain, or switch to SSH keys and skip credentials entirely. Avoid the `store` helper — it writes your token to a plaintext file.
git config --global credential.helper manager
Store credentials in the OS keychain via Git Credential Manager
Does this match your situation?
- Every push and pull prompts for a username and password.
- You keep re-pasting the same personal access token.
- Credentials are forgotten each time you restart.
Step-by-step fix
Best option — use SSH keys instead
SSH keys don't expire and never prompt once the agent has them loaded. This removes the credential question entirely rather than caching an answer to it.
step 1ssh-keygen -t ed25519 -C "you@example.com" cat ~/.ssh/id_ed25519.pub # add this at github.com/settings/keys ssh -T git@github.com git remote set-url origin git@github.com:USER/REPO.gitOr configure a keychain-backed credential helper
If you're staying on HTTPS, pick the helper for your platform. All three store the credential encrypted in the OS keychain rather than on disk in the clear.
step 2# Windows / cross-platform git config --global credential.helper manager # macOS git config --global credential.helper osxkeychain # Linux (GNOME) git config --global credential.helper libsecretCache in memory only
A middle ground when you'd rather nothing was persisted: Git holds the credential in memory for a set period and then forgets it.
step 3git config --global credential.helper 'cache --timeout=3600'Avoid the plaintext store helper
It works, but it writes your token unencrypted to ~/.git-credentials, readable by anything running as you. Use it only in a throwaway container.
step 4# NOT recommended: # git config --global credential.helper store cat ~/.git-credentials # your token, in plain textClear a stale credential
If Git is silently reusing an old, revoked token, no amount of retyping helps until the stored one is removed.
step 5git credential-manager erase # or inspect what is configured: git config --get-all credential.helper
Why this works
Git itself is stateless about authentication — it asks a credential helper, and if none is configured it falls back to prompting you every time. A helper is just a small program implementing get/store/erase, which is why the same mechanism can be backed by a keychain, an in-memory cache or a plaintext file. SSH sidesteps the whole protocol: the key exchange happens in the transport layer, so Git never has a credential to store in the first place.
How to stop it happening again
- Set up a credential helper (or SSH) as part of configuring any new machine.
- Prefer SSH on machines you own and tokens for CI, where scoping and revocation matter.
- Note token expiry dates so a silent failure doesn't surprise you months later.
Commands used in this guide
Still stuck?
Search the full command reference and every other rescue guide — there are 56 of them, covering everything from detached HEAD to force-push disasters.
Browse all guides →Frequently asked questions
How do I make Git stop asking for my password?
Either configure a credential helper backed by your OS keychain (git config --global credential.helper manager, or osxkeychain / libsecret), or switch the remote to SSH and authenticate with a key so there is no password involved at all.
Is credential.helper store safe?
Not really. It writes your token unencrypted to ~/.git-credentials, where any process running as your user can read it. Use a keychain-backed helper instead, or the in-memory cache helper if you'd rather nothing was persisted.
Why does Git still prompt after I set a helper?
Usually because the stored credential is invalid - a revoked or expired token - and the helper keeps offering it. Erase the entry for that host and Git will prompt once more, then store the new one.
Related rescue guides
Git keeps saying authentication failed even though my password is correct — why?
GitHub stopped accepting account passwords over HTTPS in August 2021. You need a personal access token in place of the password, or better, switch the remote to SSH. If it worked yesterday, a cached old credential is usually the culprit — clear it and re-authenticate.
Read the fix →Always fixablegit clone or push fails with Permission denied (publickey) — how do I fix my SSH key?
The server didn't accept any key your SSH client offered. Either you have no key, the key isn't loaded into the agent, or its public half was never added to your account. Run ssh -T git@github.com to see exactly which keys are being tried.
Read the fix →Always fixableHow do I change the remote URL of a Git repository?
git remote set-url origin <new-url> repoints an existing remote. It's a purely local change — nothing on either server is touched — so it's the safe way to switch between HTTPS and SSH, move to a new host, or fix a URL after renaming the repository.
Read the fix →Always fixableCloning takes forever — how do I clone a big repo faster?
Use --filter=blob:none for a partial clone that fetches file contents lazily, and add sparse-checkout to materialise only the directories you need. --depth 1 is fastest of all but gives you no usable history.
Read the fix →