13th july, 2025
The official docs on this are kind of complex. Here is what i do instead -
1. Install GitHub-CLI
GitHub-CLI(gh) is the official command-line for GitHub. And we can use it to easily switch git accounts.
2. GitHub-CLI as git credential-helper
Run the following command to set gh as the git credential-helper,
SIDE NOTE:
credential-helpers provide username/password to git whenever we interact with GitHub(push/pull).
- On windows, git-credential-manager is bundled with git and is installed as default credential-helper.
- On linux, we don’t get such helpers by default. I generally end up using SSH authentication there instead.
3. Add your accounts
Login into your github accounts,
4. Switch accounts
To switch to your desired account,
5. Configure git name and email on per repo basis
After switching accounts with gh auth switch, you would be able to access respective repos. But git commits will still use the global name and email.
This is a limitation of GitHub-CLI, it does not automatically updates name/email upon switching accounts. As a workaround, i remove my global git name and email using-
And for a repo related to account-1, i will go inside that repo and set the name and email once-
And repeat for other repos as per their related account.
That’s it, Enjoy!
This was a real problem for me. At some point i even had VMs for separate, headache-free, multi-account access.
GitHub-CLI is a nice offering. And i hope switching accounts also automatically configures git name and email in future.
Happy Tweaking!
.png)

