About management of multiple accounts
In some cases, you may need to use multiple accounts on GitHub. For example, you may have a personal account for open source contributions, and your employer may also create and manage a user account for you within an enterprise.
You cannot use a compte d’utilisateur managé to contribute to public projects on GitHub.com, so you must contribute to those resources using your personal account. For more information, see About Enterprise Managed Users in the GitHub Enterprise Cloud documentation.
If you need to use multiple accounts, you can stay signed in to your accounts and switch between them. For example, switching between a personal account and a service account. For more information, see Basculement entre comptes.
If you want to use one workstation to contribute from both accounts, you can simplify contribution with Git by using a mixture of protocols to access repository data, or by using credentials on a per-repository basis.
Avertissement
Be mindful when you use one workstation to contribute to two separate accounts. Management of two or more accounts can increase the chance of mistakenly leaking internal code to the public.
If you aren't required to use a compte d’utilisateur managé, GitHub recommends that you use one personal account for all your work on GitHub.com. With a single personal account, you can contribute to a combination of personal, open source, or professional projects using one identity. Other people can invite the account to contribute to both individual repositories and repositories owned by an organization, and the account can be a member of multiple organizations or enterprises.
Contributing to two accounts using HTTPS and SSH
If you contribute with two accounts from one workstation, you can access repositories by using a different protocol and credentials for each account.
Git can use either the HTTPS or SSH protocol to access and update data in repositories on GitHub. The protocol you use to clone a repository determines which credentials your workstation will use to authenticate when you access the repository. With this approach to account management, you store the credentials for one account to use for HTTPS connections and upload an SSH key to the other account to use for SSH connections.
You can find both the HTTPS or an SSH URLs for cloning a repository on the repository's page. For more information, see Clonage d’un dépôt.
For more information about the use of SSH to access repositories, see Connexion à GitHub à l’aide de SSH.
Contributing to multiple accounts using HTTPS and personal access tokens
Alternatively, if you want to use the HTTPS protocol for both accounts, you can use different personal access tokens for each account by configuring Git to store different credentials for each repository.
-
Ouvrir le terminal.
-
Pour confirmer votre utilisation d’un gestionnaire d’informations d’identification, entrez la commande suivante et notez la sortie.
Shell git config --get credential.helper
git config --get credential.helper
-
Si la sortie confirme que vous utilisez un gestionnaire d’informations d’identification, désactivez les informations d’identification stockées pour lui.
-
Si la sortie n’inclut pas le nom d’un gestionnaire d’informations d’identification, aucun gestionnaire d’informations d’identification n’est configuré et vous pouvez passer à l’étape suivante.
-
If the output is
osxkeychain
, you're using the macOS keychain. To clear the credentials, you can use the credential helper on the command line:$ git credential-osxkeychain erase host=github.com protocol=https > [Press Return] >
-
Si la production est
manager
(oumanager-core
dans les versions précédentes), vous utilisez le Gestionnaire d’informations d’identification Git. Pour effacer les informations d’identification, exécutez la commande suivante.Shell echo "protocol=https\nhost=github.com" | git credential-manager erase
echo "protocol=https\nhost=github.com" | git credential-manager erase
-
-
Pour configurer Git de sorte à mettre en cache les informations d’identification pour l’URL distante complète de chaque dépôt auquel vous accédez sur GitHub, entrez la commande suivante.
Shell git config --global credential.https://github.com.useHttpPath true
git config --global credential.https://github.com.useHttpPath true
-
Pour chacun de vos comptes, créez un personal access token (classic) dédié avec une étendue
repo
. Ou bien, pour chacun de vos comptes et pour chaque organisation dont vous êtes membre, créez un fine-grained personal access token qui peut accéder aux référentiels souhaités et qui dispose d'autorisations de lecture et d'écriture sur le contenu des référentiels. Pour plus d’informations, consultez « Gestion de vos jetons d'accès personnels ». -
La première fois que vous utilisez Git pour cloner un dépôt ou accéder à des données dans un dépôt que vous avez déjà cloné, Git demande des informations d’identification. Fournissez les personal access token pour le compte ayant accès au référentiel.
Git va mettre en cache le personal access token basé sur l’URL distante complète du dépôt et vous pourrez alors accéder aux données et en écrire sur GitHub.com à l’aide du compte approprié.
-
Open Git Bash.
-
Pour confirmer votre utilisation d’un gestionnaire d’informations d’identification, entrez la commande suivante et notez la sortie.
Shell git config --get credential.helper
git config --get credential.helper
-
Si la sortie confirme que vous utilisez un gestionnaire d’informations d’identification, désactivez les informations d’identification stockées pour lui.
- Si la sortie n’inclut pas le nom d’un gestionnaire d’informations d’identification, aucun gestionnaire d’informations d’identification n’est configuré et vous pouvez passer à l’étape suivante.
- Si la production est
manager
(oumanager-core
dans les versions précédentes), vous utilisez le Gestionnaire d’informations d’identification Git. Pour effacer les informations d’identification, exécutez la commande suivante.
Shell echo "protocol=https`nhost=github.com" | git credential-manager erase
echo "protocol=https`nhost=github.com" | git credential-manager erase
-
If the output is
wincred
, you're using the Windows Credential Manager. To clear the credentials, enter the following command.Shell cmdkey /delete:LegacyGeneric:target=git:https://github.com
cmdkey /delete:LegacyGeneric:target=git:https://github.com
-
Pour configurer Git de sorte à mettre en cache les informations d’identification pour l’URL distante complète de chaque dépôt auquel vous accédez sur GitHub, entrez la commande suivante.
Shell git config --global credential.https://github.com.useHttpPath true
git config --global credential.https://github.com.useHttpPath true
-
Pour chacun de vos comptes, créez un personal access token (classic) dédié avec une étendue
repo
. Ou bien, pour chacun de vos comptes et pour chaque organisation dont vous êtes membre, créez un fine-grained personal access token qui peut accéder aux référentiels souhaités et qui dispose d'autorisations de lecture et d'écriture sur le contenu des référentiels. Pour plus d’informations, consultez « Gestion de vos jetons d'accès personnels ». -
La première fois que vous utilisez Git pour cloner un dépôt ou accéder à des données dans un dépôt que vous avez déjà cloné, Git demande des informations d’identification. Fournissez les personal access token pour le compte ayant accès au référentiel.
Git va mettre en cache le personal access token basé sur l’URL distante complète du dépôt et vous pourrez alors accéder aux données et en écrire sur GitHub.com à l’aide du compte approprié.
-
Ouvrir le terminal.
-
Pour confirmer votre utilisation d’un gestionnaire d’informations d’identification, entrez la commande suivante et notez la sortie.
Shell git config --get credential.helper
git config --get credential.helper
-
Si la sortie confirme que vous utilisez un gestionnaire d’informations d’identification, désactivez les informations d’identification stockées pour lui.
- Si la sortie n’inclut pas le nom d’un gestionnaire d’informations d’identification, aucun gestionnaire d’informations d’identification n’est configuré et vous pouvez passer à l’étape suivante.
- Si la production est
manager
(oumanager-core
dans les versions précédentes), vous utilisez le Gestionnaire d’informations d’identification Git. Pour effacer les informations d’identification, exécutez la commande suivante.
Shell echo "protocol=https\nhost=github.com" | git credential-manager erase
echo "protocol=https\nhost=github.com" | git credential-manager erase
-
Pour configurer Git de sorte à mettre en cache les informations d’identification pour l’URL distante complète de chaque dépôt auquel vous accédez sur GitHub, entrez la commande suivante.
Shell git config --global credential.https://github.com.useHttpPath true
git config --global credential.https://github.com.useHttpPath true
-
Pour chacun de vos comptes, créez un personal access token (classic) dédié avec une étendue
repo
. Ou bien, pour chacun de vos comptes et pour chaque organisation dont vous êtes membre, créez un fine-grained personal access token qui peut accéder aux référentiels souhaités et qui dispose d'autorisations de lecture et d'écriture sur le contenu des référentiels. Pour plus d’informations, consultez « Gestion de vos jetons d'accès personnels ». -
La première fois que vous utilisez Git pour cloner un dépôt ou accéder à des données dans un dépôt que vous avez déjà cloné, Git demande des informations d’identification. Fournissez les personal access token pour le compte ayant accès au référentiel.
Git va mettre en cache le personal access token basé sur l’URL distante complète du dépôt et vous pourrez alors accéder aux données et en écrire sur GitHub.com à l’aide du compte approprié.
Contributing to multiple accounts using SSH and GIT_SSH_COMMAND
If you want to use the SSH protocol for both accounts, you can use different SSH keys for each account. For more information about using SSH, see Connexion à GitHub à l’aide de SSH.
To use a different SSH key for different repositories that you clone to your workstation, you must write a shell wrapper function for Git operations. The function should perform the following steps.
- Determine the repository's full name with owner, using a command such as
git config --get remote.origin.url
. - Choose the correct SSH key for authentication.
- Modify
GIT_SSH_COMMAND
accordingly. For more information aboutGIT_SSH_COMMAND
, see Environment Variables in the Git documentation.
For example, the following command sets the GIT_SSH_COMMAND
environment variable to specify an SSH command that uses the private key file at PATH/TO/KEY/FILE for authentication to clone the repository named OWNER/REPOSITORY on GitHub.com.
GIT_SSH_COMMAND='ssh -i PATH/TO/KEY/FILE -o IdentitiesOnly=yes' git clone git@github.com:OWNER/REPOSITORY
GIT_SSH_COMMAND='ssh -i PATH/TO/KEY/FILE -o IdentitiesOnly=yes' git clone git@github.com:OWNER/REPOSITORY