How to Update Your Git Password

Learn how to update your Git password for various authentication methods, including HTTPS with credential helpers, SSH keys, and personal access tokens.
Updating your Git password is a common task, especially when you've changed your account password on a hosting service like GitHub, GitLab, or Bitbucket. Git itself doesn't store your password directly; instead, it relies on credential helpers or SSH keys to authenticate with remote repositories. This guide will walk you through the process for different scenarios.
Understanding Git Authentication Methods
Before updating your password, it's crucial to understand how Git authenticates with remote repositories. The two primary methods are HTTPS and SSH. Each method handles credentials differently, and therefore, requires a different approach to update or reset them.
flowchart TD A[Git Operation (e.g., push)] --> B{Authentication Method?} B -- HTTPS --> C[Credential Helper] C --> D{Stored Credential?} D -- Yes --> E[Authenticate with Remote] D -- No --> F[Prompt for Username/Password] B -- SSH --> G[SSH Agent] G --> H{SSH Key Available?} H -- Yes --> I[Authenticate with Remote] H -- No --> J[Error: SSH Key Missing/Incorrect] E --> K[Success] I --> K[Success] F --> E
Git Authentication Flow
Updating Passwords for HTTPS (Credential Helpers)
When you use HTTPS to interact with a remote repository, Git often uses a credential helper to store your username and password securely. This prevents you from having to enter them every time. If you've changed your password on your Git hosting service (e.g., GitHub), you'll need to update these stored credentials.
osxkeychain
credential helper, which stores credentials in your system's Keychain Access application. On Windows, it might use wincred
or manager
.1. Clear Stored Credentials (macOS)
Open 'Keychain Access' (you can find it using Spotlight search). In the search bar, type github.com
(or your Git host's domain). Find the entry labeled internet password
for your Git host and delete it. The next time you perform a Git operation, you'll be prompted for your new credentials.
2. Clear Stored Credentials (Windows)
Open 'Credential Manager' (search for it in the Start menu). Select 'Windows Credentials'. Under 'Generic Credentials', look for entries related to git:https://github.com
(or your Git host). Expand the entry and click 'Remove'. Git will prompt for new credentials on the next operation.
3. Clear Stored Credentials (Linux/Generic)
If you're using the store
credential helper, you might have a .git-credentials
file in your home directory. You can manually edit or delete this file. Alternatively, you can use the command line to remove specific credentials:
git credential-osxkeychain erase host=github.com protocol=https
# Or for generic credential helper
git credential-cache exit
4. Perform a Git Operation
After clearing the old credentials, perform any Git operation that requires authentication, such as git pull
or git push
. Git will prompt you for your username and your new password. Enter them, and the credential helper will store the updated information.
Using Personal Access Tokens (PATs)
Many Git hosting services, like GitHub, recommend using Personal Access Tokens (PATs) instead of your account password for HTTPS authentication. PATs offer better security as they can be revoked individually and have fine-grained permissions. If you're using a PAT and it expires or you need to change it, you'll update it in the same way you would a password stored by a credential helper.
Updating Passwords for SSH Keys
SSH authentication uses SSH keys, not passwords, to connect to remote repositories. However, your SSH private key itself might be protected by a passphrase. If you want to change this passphrase, you can do so without generating a new key pair.
1. Change SSH Key Passphrase
Open your terminal and use the ssh-keygen
command with the -p
option:
ssh-keygen -p -f ~/.ssh/id_rsa
Replace ~/.ssh/id_rsa
with the path to your private key file if it's different. The command will prompt you for your old passphrase, then for your new passphrase twice.
2. Add Key to SSH Agent (if needed)
If you've changed the passphrase, you might need to re-add your key to the SSH agent to avoid entering the passphrase repeatedly during your session:
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa
This will prompt you for your new passphrase.