Configuring Multiple Github Accounts With Terminal

In this post let’s explore how we can setup multiple github ( accounts to seamlessly perform git actions without switching between accounts and re-authenticating.

Consider you have two private github accounts hosted in

Default behavior,
In order to perform git operations (pull, push, clone, etc) on repositories hosted under one account you need authenticate using the credentials of that account, and each time you need to switch to the other account (on the same git provider) you need to authenticate again. This hinders the productivity and workflow.

Hmm… How can we overcome this and seamlessly work with repositories hosted on multiple accounts?

Before we jump into the details, to get an overview of git and how git credentials are stored refer to my blog

By Default: Git Only Considers the Domain name when Storing Credentials

By default gitcredentials only considers the domain name.
So, if you have two different git accounts in two different git providers ( and then you can seamlessly work with both accounts as gitcredentials configures two different git credential helpers for each domain with their own credentials.

For example, the .gitconfig file would have the following entries if you are using two different git accounts from two different git providers,

[credential ""]
helper = osxkeychain
[credential ""]
helper = osxkeychain

Since there are two git credential helpers for each domain we can use two different accounts across git providers seamlessly.

But this doesn’t help much on our use-case of seamlessly working with two different git accounts on same git provider (, as there will be only one git credential helper thus storing only one set of credentials.

Configure Git to consider the full Http path

By default, Git does not consider the “path” component of an http URL

This means that a credential stored for will also be used for, this is the reason we can’t use different accounts with the same git provider.

In order to overcome this, we can configure git credentials helper to consider the full path by setting the “useHttpPath” variable to true.

Execute the following commands from the terminal to setup git credential helper to consider full Http path,

Configure Git Credential Helper for “” with “osxkeychain” to store the credentials,

git config --global osxkeychain

Configure the “” credential helper to use full http path,

git config --global true

With the useHttpPath configuration git will consider each url as unique and store the credentials for each url separately in the keychain.

Using this we can set two separate credentials for<organizationA>/foo.git and<organizationB>/bar.git repositories and seamlessly perform git operations.

Changing this setting will ask your credentials for each URL (for which the credential is not stored yet). Even if you are accessing two git repositories with same git account you need to provide the credentials for each url the first time.

The .gitconfig file will have the following entries after setting up the useHttpPath,

[credential ""]
useHttpPath = true
helper = osxkeychain

Hope you enjoyed the blog and able to set up multiple github ( accounts to seamlessly work with Terminal.

Thank you for reading!


Senior Software Engineer @WSO2, B.Sc.(Hons).Computer Engineering