How to Change Git Account in the Terminal: A Practical Guide

If you use Git for multiple projects—personal, work, or open-source—you may need to switch Git accounts from the terminal. Whether you’re moving from one GitHub account to another, switching to GitLab, or using different credentials for different repositories, managing Git identities via the command line is essential.

In this guide, we’ll show you how to change your Git account in the terminal, for both global and repository-specific configurations.


✅ Step 1: Check Your Current Git Account

To see your current Git username and email:

git config --global user.name
git config --global user.email

This shows the global Git identity—used by default for all repositories.


🔄 Step 2: Change Git Account Globally

To update your Git account details across all repositories:

git config --global user.name "Your New Name"
git config --global user.email "[email protected]"

You can verify the change:

git config --global --list

Use this when you’re switching accounts system-wide.


🔁 Step 3: Change Git Account for a Specific Repository

If you only want to change the Git identity for one repo:

cd path/to/your/repo

git config user.name "Your Repo-Specific Name"
git config user.email "[email protected]"

Check the config:

git config --list --local

This is ideal when managing multiple GitHub/GitLab accounts on the same machine.


🔐 Step 4: Update Stored Credentials (Optional)

If you use HTTPS and Git is caching old credentials, clear them:

On macOS:

git credential-osxkeychain erase
host=github.com
protocol=https

On Windows:

Go to Credential Manager → Find GitHub → Remove stored credentials.

On Linux:

Remove the .git-credentials file or use:

git config --global --unset credential.helper

You’ll be prompted to enter your username/password again on the next push.


🔑 Step 5: (Optional) Use SSH for Managing Multiple Accounts

Using SSH keys helps avoid conflicts between multiple accounts.

Generate a new SSH key:

ssh-keygen -t ed25519 -C "[email protected]"

Save it with a custom name (e.g., id_ed25519_work), then add it to your Git config and SSH agent.

You can configure SSH to map hostnames to specific accounts in ~/.ssh/config:

Host github-work
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_ed25519_work

Then, clone using:

git clone git@github-work:username/repo.git

✅ Summary

TaskCommand/Action
Set global accountgit config --global user.name/email
Set repo-specific accountgit config user.name/email in the repo folder
List current configgit config --list
Remove stored credentials (Windows)Use Credential Manager
Use SSH for multiple accountsSet up keys + ~/.ssh/config customization

🚀 Final Thoughts

Managing multiple Git accounts from the terminal is easier when you understand how Git configurations work. Use global settings for simplicity, repository-specific settings for flexibility, and SSH keys for security and account separation.

Sharing Is Caring:

Leave a Comment