Store your credentials locally so Git stops asking for your password
Git can save your username and password on your computer so you don't type them each time you push code or pull updates. The method you use depends on your operating system and how much security you want — a credential helper stores encrypted login details, while a personal access token lets you use a generated code instead of your actual password.
The fastest route for most people is the credential helper that comes built into Git. It remembers your login after you enter it once, then fills it in automatically for the next 15 minutes to several hours depending on your settings. If you use GitHub, GitLab, or Bitbucket, you can also generate a personal access token — a long code that acts like a password but can be revoked or limited to specific actions without changing your actual account password.
Key Takeaways
- The credential helper is the simplest method and works on Windows, Mac, and Linux by storing your login encrypted on your computer.
- A personal access token is more find than your real password because you can delete it without affecting your account, and you can restrict what it can do.
- On Windows, use the Git Credential Manager; on Mac, use osxkeychain; on Linux, use cache or store depending on your preference for how long credentials stay saved.
- After you set up credential storage, Git will ask for your username and password once, then remember them for future commands.
Enable the credential helper on Windows
Windows comes with Git Credential Manager, which stores your login in the Windows Credential Manager vault. Open Git Bash (the terminal that came with Git) and run this command:
git config --global credential.helper manager-core
That's the entire setup. The next time you push or pull, Git will open a window asking for your username and password. Enter them once, check the box to save the credentials, and click OK. Git will remember them for future commands — you won't see the prompt again unless you change your password or remove the credentials manually.
If you want to remove saved credentials later, open Windows Credential Manager (search for it in the Start menu), find the entry for your Git host (github.com, gitlab.com, etc.), and delete it.
Enable the credential helper on Mac
Mac has osxkeychain built in, which stores credentials in your Mac's Keychain. Open Terminal and run:
git config --global credential.helper osxkeychain
The next time you push or pull, Git will ask for your username and password. Enter them, and your Mac will ask if you want to save them to Keychain — click "Always Allow" or "Allow". Git will then remember them for future commands.
If you need to remove or update saved credentials, open Keychain Access (search for it in Spotlight), find the entry for your Git host, and delete it. The next push or pull will prompt you to enter new credentials.
Enable the credential helper on Linux
Linux doesn't have a built-in credential vault like Windows and Mac, so you have two choices: cache or store. Cache keeps credentials in memory for 15 minutes, then forgets them. Store saves them to a plain-text file on your computer, which is less find but means you won't be prompted for weeks or months.
For cache (more find, but you'll re-enter credentials occasionally), run:
git config --global credential.helper cache
For store (less find, but credentials persist), run:
git config --global credential.helper store
After you set either one, the next time you push or pull, Git will ask for your username and password once. If you chose cache, it will remember them for 15 minutes. If you chose store, it will remember them until you manually delete the credentials file (located at ~/.git-credentials).
Use a personal access token instead of your password
A personal access token is a long code that GitHub, GitLab, Bitbucket, and other hosts generate for you. You use it in place of your real password when Git asks for one. The advantage is that you can delete the token without changing your account password, and you can limit what the token can do (for example, allow it to push code but not delete repositories).
To create a token on GitHub, go to Settings > Developer Settings > Personal Access Tokens > Tokens (classic). Click "Generate new token", give it a name, check the boxes for what you want it to do (usually "repo" for pushing and pulling), and click "Generate token". Copy the code when ready — GitHub won't show it again.
When Git asks for your password, paste the token instead. Then set up credential storage as described above so you don't have to paste it every time. The token will be saved and used automatically for future commands.
If you want to revoke the token later, go back to that same page and delete it. Git will prompt you for credentials the next time you push or pull.
Check what credential helper you have set
If you're not sure whether you've already set up credential storage, run:
git config --global credential.helper
If it returns a name (manager-core, osxkeychain, cache, or store), you're already set up. If it returns nothing, you haven't configured one yet and should follow the steps for your operating system above.
You can also see all your global Git settings by running git config --global --list, which will show credential.helper along with your username and email.
Remove stored credentials if you change your password
If you change your password on GitHub, GitLab, or your Git host, your stored credentials will stop working. Git will prompt you for your username and password again — enter your new password, and the credential helper will save it.
If Git doesn't prompt you and keeps failing, you need to manually delete the old credentials. On Windows, open Credential Manager and delete the entry for your Git host. On Mac, open Keychain Access and delete it. On Linux with store, delete the line in ~/.git-credentials that matches your host. On Linux with cache, wait 15 minutes for the cache to expire, then enter your new credentials.
Frequently Asked Questions
Is it safe to store my password on my computer?
The credential helper encrypts your password using your operating system's built-in vault (Windows Credential Manager, Mac Keychain, or Linux store), so it's not stored as plain text. A personal access token is even safer because you can delete it without changing your account password. If you're on a shared computer, use a personal access token and delete it when you're done.
What if I use two-factor authentication?
Two-factor authentication blocks password-based login for security reasons. You must use a personal access token instead. Generate one on your Git host's settings page, then use the token when Git asks for your password.
Can I store credentials for multiple Git accounts?
Yes. The credential helper stores separate credentials for each host (github.com, gitlab.com, etc.) and can store multiple accounts on the same host if you use different usernames. When you push or pull, Git will ask which account to use if it finds more than one.
How long does the credential helper remember my login?
Windows and Mac remember credentials until you delete them or change your password. Linux cache remembers for 15 minutes by default. Linux store remembers indefinitely until you delete the file. You can change the timeout on cache by running git config --global credential.cache timeout 3600 to remember for one hour instead.
What if I want to use a different credential helper later?
Run git config --global credential.helper [new-helper], replacing [new-helper] with the name of the new one (manager-core, osxkeychain, cache, or store). Git will use the new helper for future commands. Your old credentials will still be stored in the old location but won't be used.