Setup & configAlways fixable

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.

quick fix
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

  1. 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 1
    ssh-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.git
    
  2. Or 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 libsecret
    
  3. Cache 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 3
    git config --global credential.helper 'cache --timeout=3600'
    
  4. 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 text
    
  5. Clear a stale credential

    If Git is silently reusing an old, revoked token, no amount of retyping helps until the stored one is removed.

    step 5
    git 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

git credential / credential.helper

Stop Git asking for your username and password on every push.

git config

Read and write Git settings for one repo, your user, or the whole machine.

git remote

Manage the named URLs your repository syncs with.

git push

Upload your commits to the remote repository.

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

← All Git Rescue guides