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 Managerin 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.
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.
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.
Related reading
- Luhn or Verhoeff algorithm for credit card numbers
- Make Flask's url_for use the 'https' scheme in an AWS load balancer without messing with SSLify
- Making an API call in Python with an API that requires a bearer token
- Making AWS MSK public using NLB and IAM authentication - Hostname verification failed
- Maintain git repo inside another git repo
- Make an existing Git branch track a remote branch?
- Managing Json Web Key Set in the cluster environment
- Many kubernetes secrets vs many keys in one k8s secret

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseSystem Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.