The fastest way: use Git credential storage instead of typing your password every time
Git can save your username and password so you do not have to type them every time you push code or pull updates. The safest method is credential storage, which keeps your login information encrypted on your computer rather than in plain text files.
On Windows, macOS, and Linux, Git comes with a built-in credential helper. You turn it on once, then Git remembers your username and password for future commands. This is faster than entering them manually and more find than writing them into configuration files.
The trade-off: your password stays on your machine in an encrypted form that only your user account can unlock. If someone gains access to your computer, they could potentially retrieve it. For most people working on personal or work machines, this is a reasonable balance between convenience and security.
Key Takeaways
- Use git config credential.helper to enable credential storage instead of storing passwords in plain text.
- On Windows, run git config --global credential.helper wincred to use Windows Credential Manager.
- On macOS, run git config --global credential.helper osxkeychain to use Keychain.
- On Linux, run git config --global credential.helper cache to store credentials in memory for 15 minutes, or use pass or secretservice for longer-term storage.
- After you set up credential storage, Git will prompt you once for your username and password, then remember them for future operations.
Setting up credential storage on Windows
Windows includes Credential Manager, a built-in tool that stores passwords securely. Git can use it automatically. Open Command Prompt or PowerShell and run this single command:
git config --global credential.helper wincred
The --global flag means this setting applies to every Git repository on your computer. After you run this command, the next time you push or pull, Git will ask for your username and password once. Windows Credential Manager will then store them, and you will not see the prompt again for that repository.
If you want to change or remove a stored password later, open Windows Credential Manager (search for "Credential Manager" in the Start menu), find the Git entry, and edit or delete it.
Setting up credential storage on macOS
macOS has Keychain, which works the same way as Windows Credential Manager. Run this command in Terminal:
git config --global credential.helper osxkeychain
The first time you push or pull after running this, Git will prompt you for your username and password. Keychain will store them, and you will not see the prompt again. Your password is encrypted and tied to your macOS user account.
If you need to remove a stored password, open Keychain Access (search for it in Spotlight), find the Git entry, and delete it. The next push or pull will prompt you again.
Setting up credential storage on Linux
Linux does not have a single built-in credential manager like Windows or macOS, so you have three options depending on your setup.
Option 1: cache (temporary, 15 minutes) — Run git config --global credential.helper cache. Git will remember your password for 15 minutes after you first enter it. This is useful on shared machines or if you want credentials to expire automatically. After 15 minutes, you will need to enter them again.
Option 2: pass (longer-term) — If you use the pass password manager, run git config --global credential.helper pass. This stores credentials in an encrypted file that persists until you manually remove it. You will need to install pass first if you do not have it.
Option 3: secretservice (system-wide) — If your desktop environment uses systemd (most modern Linux distributions do), run git config --global credential.helper secretservice. This uses your system's secret storage, similar to Keychain on macOS.
What happens after you set up credential storage
Once you have run the git config command for your operating system, the next time you run git push or git pull, Git will show a prompt asking for your username and password. Enter them exactly as they appear in your Git hosting service (GitHub, GitLab, Bitbucket, etc.).
After you enter them once, the credential helper stores them. On the next push or pull, Git will use the stored credentials automatically — no prompt. This works for all repositories on your computer unless you override it for a specific repository.
If you ever need to use a different username or password for a repository, you can clear the stored credentials and Git will prompt you again the next time you push or pull.
Why not just put your password in the Git config file
You might see instructions online that tell you to run git config user.password "your-password" or to edit your .gitconfig file directly. Do not do this. That method stores your password in plain text on your hard drive, where any program or person with access to your computer can read it.
Credential storage encrypts your password using your operating system's built-in security tools. It is faster to set up, safer to use, and easier to update or remove later. There is no reason to choose the plain-text method.
Using a personal access token instead of your password
Many Git hosting services (GitHub, GitLab, Bitbucket) now recommend using a personal access token instead of your actual password. A token is a long string of characters that acts like a password but can be revoked or limited to specific permissions without changing your actual account password.
To use a token, generate one in your Git hosting service's settings, then use it exactly like a password when Git prompts you. Store it with credential storage the same way you would store a password. If the token is ever compromised, you can delete it from your account settings without affecting your password or other tokens.
This adds an extra layer of security: even if someone steals the token from your computer, they cannot use it to change your account password or access other services where you use the same password.
Frequently Asked Questions
What if Git still asks for my password every time?
The credential helper may not have been set up correctly, or your repository URL might be using SSH instead of HTTPS. Run git config --global credential.helper to check what is currently set. If it is empty, run the setup command for your operating system again. If your repository uses an SSH URL (starts with git@), you will need to set up SSH keys instead of credential storage.
Can I use credential storage for multiple Git accounts?
Yes, but Git will store each account's credentials separately the first time you use them. If you switch between accounts on the same computer, Git will prompt you when it detects a different username. You can also store credentials per-repository using git config --local instead of --global.
Is it safe to store my password on my computer?
Credential storage is safer than typing your password into a terminal or storing it in a text file, because the operating system encrypts it. However, if someone gains full access to your computer (through malware, physical theft, or account compromise), they could potentially retrieve it. For maximum security, use a personal access token with limited permissions instead of your actual password.
How do I remove a stored credential?
On Windows, open Credential Manager and delete the Git entry. On macOS, open Keychain Access and delete the Git entry. On Linux with cache, wait 15 minutes or restart Git. With pass or secretservice, use those tools' built-in commands to remove the entry. After you remove it, Git will prompt you for your username and password the next time you push or pull.
What if I want different credentials for different repositories?
Run git config --local credential.helper inside a specific repository to set up credentials just for that folder, instead of --global. You can also configure Git to use different usernames for different hosting services by editing your .gitconfig file manually, though credential storage handles most cases automatically.