Stop Git from asking for credentials on every push

Configure an HTTPS credential helper or SSH key for GitHub, manage expired tokens, and troubleshoot repeated authentication prompts.

Best practices
Illustration of Git branches and version history

For HTTPS, configure a credential helper that works with your operating system. Alternatively, use SSH with a registered key and an SSH agent. Either approach can avoid repeated prompts, but tokens can expire and a passphrase-protected SSH key may still need to be unlocked.

The examples below use GitHub. Other Git hosting services can have different authentication and single sign-on requirements.

Use SSH

Generate a key if you do not already have an appropriate one. Do not overwrite an existing key when prompted:

ssh-keygen -t ed25519 -C "your_email@example.com"
cat ~/.ssh/id_ed25519.pub

Add the public key in GitHub under Settings → SSH and GPG keys. Keep the private key on your machine. Load it into a running SSH agent when needed:

ssh-add ~/.ssh/id_ed25519

Then update the remote and test authentication, replacing OWNER/REPOSITORY with your repository:

git remote set-url origin git@github.com:OWNER/REPOSITORY.git
ssh -T git@github.com

Check GitHub's published host-key fingerprints before accepting a new host key. A successful test identifies your account; GitHub does not provide an interactive shell through this connection.

Keep HTTPS and configure a helper

Inspect existing configuration before adding another helper:

git config --show-origin --get-all credential.helper

Choose the command appropriate to an installed helper:

# macOS: store credentials in Keychain.
git config --global credential.helper osxkeychain

# Git Credential Manager, when installed and configured.
git config --global credential.helper manager

# Linux/Unix: keep credentials in memory for one hour.
git config --global credential.helper 'cache --timeout=3600'

These are alternatives. A helper name does not install the corresponding program. Git Credential Manager can guide you through browser-based authentication; when GitHub asks for a password for HTTPS Git access, use a personal access token instead of your account password. Grant only the repository access and permissions needed for the operation.

The in-memory cache expires and does not survive a restart. Avoid credential.helper store when you need encrypted storage: it writes credentials in plaintext.

FAQ

How do I see which protocol I use?

Run git remote -v. https://github.com/... uses HTTPS; git@github.com:... and ssh://... use SSH. Check the push URL as well as the fetch URL.

Why did prompts return after my token expired?

Replace the expired credential in the configured helper. On macOS, inspect the matching GitHub entry in Keychain Access; on Windows, use the configured credential manager. Target the correct account, especially if several accounts share the same host. Your next authenticated operation can store the replacement.

What if my company blocks SSH port 22?

GitHub.com supports SSH at ssh.github.com on port 443. Test that endpoint before changing configuration:

ssh -T -p 443 git@ssh.github.com

A corresponding SSH configuration is:

Host github.com
    HostName ssh.github.com
    Port 443
    User git

This is a GitHub.com facility, not a universal rule for self-hosted Git servers. Some HTTP proxies also block SSH on port 443.

See Git credential helpers, GitHub authentication, and SSH over HTTPS port.

Get a tailored plan

Contact us

Join the community

Scan with WeChat
to join the community

Try Guance

Start online and pay only for what you use.

Get started

Choose a Guance plan

Code hosting