Git
password update
Git tutorial
repository security
version control

How to change or update your Git password (stored credentials)

Codemia Knowledge Hub ·

To update your Git password, update or clear the stored credential in your credential helper: Keychain Access on macOS, Windows Credential Manager on Windows, and usually the store or cache helper on Linux. The next Git operation that needs authentication then prompts for the new password or personal access token.

GitHub, GitLab and Bitbucket have all moved away from plain passwords for HTTPS. On those services your "password" is almost certainly a personal access token (PAT), not your login password. Updating it works the same way.

Step 1: find your credential helper

bash
git config --get credential.helper
OutputPlatformStorage Location
osxkeychainmacOSKeychain Access app
manager or manager-coreWindows / cross-platformWindows Credential Manager or GCM
storeLinux (common)Plain text file at ~/.git-credentials
cacheLinux (common)In-memory, expires after timeout
(empty)AnyNo helper configured; Git prompts every time

If nothing is returned, no credentials are stored and Git prompts on every authenticated operation, so there is nothing to update.

Step 2: update the credential for your platform

macOS (osxkeychain)

Delete the old credential and let Git prompt for the new one:

bash
1git credential-osxkeychain erase
2host=github.com
3protocol=https
4

Press Enter after protocol=https, then Enter again on a blank line to send the input. The next git push or git pull asks for your username and token.

Or open Keychain Access, search for github.com (or your Git host), and edit the password field.

Windows (Credential Manager / GCM)

  1. Go to Control Panel > User Accounts > Credential Manager.
  2. Select Windows Credentials (or Generic Credentials).
  3. Find the entry for your Git host, such as git:https://github.com.
  4. Click Edit and replace the password with your new token.

Or remove the credential from the command line and let Git re-prompt:

bash
1git credential reject
2host=github.com
3protocol=https
4

With Git Credential Manager (GCM), the next push may open a browser-based OAuth flow instead of a terminal prompt.

Linux (store helper)

The store helper keeps credentials in plain text at ~/.git-credentials:

bash
cat ~/.git-credentials

Each line looks like:

text
https://username:[email protected]

Replace the old token with the new one, or start fresh:

bash
rm ~/.git-credentials

The next authenticated operation prompts and recreates the file.

Linux (cache helper)

The cache helper holds credentials in memory with a timeout. Clear it to force a prompt:

bash
git credential-cache exit

Step 3: verify the new credential

bash
git ls-remote https://github.com/your-username/your-repo.git

A list of refs means authentication worked. Another prompt or an authentication error means the token or password is wrong.

Using a personal access token instead of a password

Most major hosts require a PAT for HTTPS. If the terminal asks for a "password", enter the PAT.

To create one on GitHub:

  1. Go to Settings > Developer Settings > Personal access tokens > Tokens (classic).
  2. Click Generate new token.
  3. Select the required scopes (at minimum, repo for private repositories).
  4. Copy the token and use it wherever Git asks for a password.

On GitLab, use Settings > Access Tokens. On Bitbucket, Personal Settings > App passwords.

Switching to SSH

SSH keys remove password and token handling from Git operations entirely:

bash
1# Generate an SSH key pair
2ssh-keygen -t ed25519 -C "[email protected]"
3
4# Start the SSH agent and add your key
5eval "$(ssh-agent -s)"
6ssh-add ~/.ssh/id_ed25519
7
8# Copy the public key to your clipboard (macOS)
9pbcopy < ~/.ssh/id_ed25519.pub

Add the public key in your Git host's SSH key settings, then change the remote URL:

bash
git remote set-url origin [email protected]:your-username/your-repo.git

Git now authenticates with your key and never asks for a password or token.

Credential helpers compared

HelperPersistenceSecuritySetup Effort
osxkeychainPermanent until deletedEncrypted in KeychainNone (default on macOS)
manager-core (GCM)Permanent until deletedOS credential storeIncluded with Git for Windows
storePermanent until deletedPlain text on diskMinimal
cacheTemporary (default 15 min)In-memory onlyMinimal
SSH keysPermanentPrivate key on diskModerate

Why the new password is rejected

You entered your account password, not a PAT. GitHub deprecated password authentication for HTTPS in August 2021. Use a personal access token.

git credential-osxkeychain erase is hanging. It reads stdin and waits for a blank line to end input. Press Enter on an empty line.

~/.git-credentials got corrupted. Editors that add trailing whitespace or newlines can break it. Use a reliable editor, or delete the file and let Git recreate it.

You use different accounts for different repositories. Set credentials per repository with git config --local credential.helper inside each repo instead of globally.

The old token is still valid. Updating it locally does not revoke it on the server. Revoke the previous token in your Git host's settings after rotating.


Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design