Git
password update
Git tutorial
repository security
version control

How do I update the password for Git?

System Design practice on Codemia

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

Practice system design

Introduction

To update your Git password, you need to update or clear the stored credentials in whatever credential helper your system uses. On macOS that is Keychain Access, on Windows it is Windows Credential Manager, and on Linux it is typically the store or cache helper. After clearing or updating the stored credential, the next Git operation that requires authentication will prompt you for the new password or personal access token.

Note that GitHub, GitLab, and Bitbucket have all moved away from plain passwords for HTTPS authentication. If you are using one of these services, your "password" is almost certainly a personal access token (PAT), not your account login password. Updating it follows the same credential-helper workflow described below.

Step 1: Identify Your Credential Helper

Before you can update anything, find out how Git is storing your credentials.

bash
git config --get credential.helper

Common outputs and what they mean:

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, Git has no credential helper and will prompt on every authenticated operation. In that case, there is nothing to update since no credentials are stored.

Step 2: Update Credentials by Platform

macOS (osxkeychain)

The simplest approach is to delete the old credential and let Git prompt you for the new one.

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

You must press Enter after protocol=https and then press Enter again on a blank line to send the input. After this, the next git push or git pull will prompt for your username and token.

Alternatively, open Keychain Access, search for github.com (or your Git host), and update the password field directly.

Windows (Credential Manager / GCM)

Open the Windows Credential Manager through Control Panel:

  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.

You can also remove the credential from the command line and let Git re-prompt:

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

If you are using Git Credential Manager (GCM), it may open a browser-based OAuth flow on the next push instead of a terminal prompt.

Linux (store helper)

The store helper saves credentials in plain text at ~/.git-credentials. You can edit the file directly.

bash
cat ~/.git-credentials

Each line follows this format:

text
https://username:[email protected]

Replace the old token with the new one. If you prefer to start fresh:

bash
rm ~/.git-credentials

The next authenticated Git operation will prompt for credentials and recreate the file.

Linux (cache helper)

The cache helper stores credentials in memory with a configurable timeout. To force a re-prompt, clear the cache:

bash
git credential-cache exit

After this, the next Git operation will ask for credentials again.

Step 3: Verify the Update

After updating your credentials, confirm they work:

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

If authentication succeeds, you will see a list of refs. If it fails, Git will either prompt again or return an authentication error, which means the token or password you entered is incorrect.

Switching from Password to Personal Access Token

Most major Git hosts now require personal access tokens instead of passwords for HTTPS operations. If you are still being asked for a "password" at the terminal, you should enter your PAT, not your account password.

To generate a PAT 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, the path is Settings > Access Tokens. On Bitbucket, it is Personal Settings > App passwords.

Switching to SSH Instead

If managing HTTPS tokens feels cumbersome, SSH keys eliminate password and token management entirely for Git operations.

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 to your Git host's SSH key settings. Then update your remote URL:

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

After this, Git authenticates via your SSH key and never asks for a password or token.

Credential Helper Comparison

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

Common Pitfalls

Entering your account password instead of a PAT. GitHub deprecated password authentication for HTTPS in August 2021. If you type your GitHub login password, authentication will fail. Use a personal access token instead.

Forgetting to press Enter on a blank line when using git credential-osxkeychain erase. The command reads from stdin and expects a blank line to terminate input. Without it, the command hangs waiting for more input.

Editing ~/.git-credentials with a text editor that adds trailing whitespace or newlines. Invisible characters can corrupt the credential file. Use a reliable editor or delete the file entirely and let Git recreate it.

Updating credentials globally when you use different accounts for different repositories. If you contribute to repos under multiple GitHub accounts, set credentials per-repository rather than globally. Use git config --local credential.helper inside each repo.

Not revoking old tokens after rotation. Updating your local credential does not invalidate the old token on the server. Always revoke the previous token from your Git host's settings after generating a new one.

Summary

Updating your Git password or token is a credential-helper operation, not a Git configuration change. Identify your credential helper with git config --get credential.helper, then clear or update the stored credential through the appropriate mechanism for your OS. Verify the update with git ls-remote. For long-term convenience, consider switching to SSH keys or using Git Credential Manager, which handles token refresh and OAuth flows automatically. Always revoke old tokens on the server side after rotating credentials locally.


Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

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

View the course
Track 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.

Practice system design

All Rights Reserved.