git bash
logout
login
user authentication
version control

How to log out and log in as another user in Git Bash

Codemia Knowledge Hub ·

To log out of Git in Git Bash and switch to another account, remove the stored credentials and authenticate again as the new user. On Windows, delete the Git entries in Credential Manager, set the user identity for the repository, and then sign in with an SSH key or a personal access token (PAT) for the new account.

How Git authenticates

Git verifies you to remote repositories with one of two methods:

  • SSH keys: Secure and often preferred for GitHub, GitLab, or Bitbucket.
  • HTTP(S) authentication: Uses a username and personal access token instead of a password.

Both can be configured in Git Bash when switching users.

Step 1: Clear cached credentials

Git caches credentials for convenience, which gets in the way when you switch users.

  • Delete cached credentials: Open Control Panel -> User Accounts -> Credential Manager in Windows and remove any credentials related to Git.

Step 2: Set the user identity and new credentials

Each repository can have its own user name and email in its local configuration. This does not affect the global configuration and keeps identity consistent per repository.

bash
git config user.name "New User"
git config user.email "[email protected]"

With SSH:

  • Generate a new SSH key if you don't have one for the new account.
  • Add the SSH key to the SSH agent: Start the ssh-agent and add your private key.
  • Update the remote URL in the repository to use SSH.
bash
1ssh-keygen -t ed25519 -C "[email protected]"
2eval "$(ssh-agent -s)"
3ssh-add ~/.ssh/id_ed25519
4git remote set-url origin [email protected]:owner/repo.git

With HTTPS:

  • Create a PAT: Log into your Git provider and create a token with the necessary permissions.
  • Use the PAT for authentication: When prompted for a password, enter the PAT instead.

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