How can I save username and password in Git?
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
Saving Git credentials can remove a lot of repetitive prompts, but it is also a security-sensitive task. In modern Git workflows, the practical goal is usually to store a username and token through a credential helper, or to avoid HTTPS secrets entirely by using SSH keys.
Understand What “Password” Usually Means Now
Most major Git hosting services no longer accept normal account passwords for HTTPS Git operations. In practice, the “password” field is usually one of these:
- a personal access token
- a temporary enterprise token
- a single sign-on backed credential
So when people ask to save their Git password, the safe interpretation is usually “store my Git username and token securely.”
Configure a Credential Helper
Git credential helpers remember credentials for you and hand them back to Git when needed. The right helper depends on the operating system.
Check the current helper:
Set a helper:
After this, the next authenticated Git operation should prompt once and then store the credential through the selected helper.
Use a Token Over HTTPS
If your remote uses HTTPS, the common workflow is to enter the account name as the username and paste a personal access token into the password prompt.
Once the helper is configured, Git will store that token securely according to the helper’s storage backend instead of asking every time.
Use the In-Memory Cache for Temporary Storage
If you want the convenience of saved credentials without long-term persistence, Git also supports an in-memory cache.
This remembers credentials for one hour and then forgets them. It is less convenient than a keychain-backed helper, but it is useful on shared or sensitive systems where long-term storage is undesirable.
Avoid Plaintext Storage Unless the Environment Is Disposable
Git can also store credentials directly in a plaintext file:
That works, but it writes secrets to disk in readable form. It may be acceptable on a disposable lab machine, but it is a poor default on developer laptops or shared systems.
If you already enabled it in the past, consider removing it and switching to a secure helper instead.
SSH Is Often Better for Frequent Git Use
If you work with many repositories or want to avoid HTTPS tokens entirely, SSH keys are often a better long-term setup.
Then change the remote URL:
SSH removes most repeated credential prompts and avoids storing HTTPS tokens in the first place.
Check and Troubleshoot Credential Configuration
If Git still prompts unexpectedly, inspect the effective configuration and the remote URL style.
A common cause of confusion is mixing global and repository-local credential settings or using SSH in one repository and HTTPS in another.
Rotate and Revoke Credentials Deliberately
Stored credentials are part of your security surface. Rotate tokens when:
- a device is lost
- a role changes
- a token scope was too broad
- a security incident occurs
Credential helpers make day-to-day work easier, but they do not remove the need for good token hygiene.
Common Pitfalls
The biggest mistake is trying to store a normal account password when the hosting provider expects a token. Another is using the plaintext store helper on a machine where secure storage is available. Developers also forget that SSH is often a cleaner solution than storing HTTPS secrets at all.
Summary
- Use a credential helper if you want Git to remember HTTPS credentials.
- In modern setups, the saved secret is usually a token rather than a normal password.
- Prefer OS-backed helpers such as Git Credential Manager or the macOS keychain helper.
- Use the in-memory cache when you want temporary rather than persistent storage.
- Consider SSH keys if you want a long-term passwordless workflow.
Related reading
- How can I securely download a private S3 asset onto a new EC2 instance with cloudinit?
- How can I set up a letsencrypt SSL certificate and use it in a Spring Boot application?
- How can I specify my .keystore file with Spring Boot and Tomcat?
- How can I use custom client certificate for external service with istio?
- How can I search Git branches for a file or directory?
- How can I see the changes in a Git commit?
- How can I use different certificates on specific connections?
- How can I use Laravel Sanctum in a distributed system?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.