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.
-
ターミナルを開きます。
-
資格情報マネージャーを使用していることを確認するには、次のコマンドを入力し、出力をメモします。
Shell git config --get credential.helper
git config --get credential.helper
-
出力で資格情報マネージャーを使用していることが確認された場合は、資格情報マネージャーの保存された資格情報をクリアします。
-
出力に資格情報マネージャーの名前が含まれていない場合は、資格情報マネージャーが構成されていないため、次の手順に進むことができます。
-
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] >
-
出力が
manager
(前のバージョンではmanager-core
) の場合は、Git Credential Manager を使用しています。 資格情報をクリアするには、次のコマンドを実行します。Shell echo "protocol=https\nhost=github.com" | git credential-manager erase
echo "protocol=https\nhost=github.com" | git credential-manager erase
-
-
GitHub でアクセスする各リポジトリの完全なリモート URL の資格情報をキャッシュするように Git を構成するには、次のコマンドを入力します。
Shell git config --global credential.https://github.com.useHttpPath true
git config --global credential.https://github.com.useHttpPath true
-
アカウントごとに
repo
スコープを持つ専用の personal access token (classic) を作成します。 または、アカウントごと、自分がメンバーになっている organization ごとに、目的のリポジトリへのアクセスが可能で、リポジトリの内容に対する読み取りと書き込みのアクセス許可を持っている fine-grained personal access token を作成します。 詳しくは、「個人用アクセス トークンを管理する」をご覧ください。 -
Git を使用してリポジトリをクローンしたり、既にクローンしたリポジトリ内のデータにアクセスしたりすると、Git によって資格情報が要求されます。 リポジトリに対してアクセス権を持つアカウントの personal access token を指定してください。
Git を使い、リポジトリのフル リモート URL に基づいてpersonal access tokenをキャッシュします。こうすることで、正しいアカウントを使って、リポジトリ データにアクセスして GitHub.com に書き込むことができるようになります。
-
Open Git Bash.
-
資格情報マネージャーを使用していることを確認するには、次のコマンドを入力し、出力をメモします。
Shell git config --get credential.helper
git config --get credential.helper
-
出力で資格情報マネージャーを使用していることが確認された場合は、資格情報マネージャーの保存された資格情報をクリアします。
- 出力に資格情報マネージャーの名前が含まれていない場合は、資格情報マネージャーが構成されていないため、次の手順に進むことができます。
- 出力が
manager
(前のバージョンではmanager-core
) の場合は、Git Credential Manager を使用しています。 資格情報をクリアするには、次のコマンドを実行します。
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
-
GitHub でアクセスする各リポジトリの完全なリモート URL の資格情報をキャッシュするように Git を構成するには、次のコマンドを入力します。
Shell git config --global credential.https://github.com.useHttpPath true
git config --global credential.https://github.com.useHttpPath true
-
アカウントごとに
repo
スコープを持つ専用の personal access token (classic) を作成します。 または、アカウントごと、自分がメンバーになっている organization ごとに、目的のリポジトリへのアクセスが可能で、リポジトリの内容に対する読み取りと書き込みのアクセス許可を持っている fine-grained personal access token を作成します。 詳しくは、「個人用アクセス トークンを管理する」をご覧ください。 -
Git を使用してリポジトリをクローンしたり、既にクローンしたリポジトリ内のデータにアクセスしたりすると、Git によって資格情報が要求されます。 リポジトリに対してアクセス権を持つアカウントの personal access token を指定してください。
Git を使い、リポジトリのフル リモート URL に基づいてpersonal access tokenをキャッシュします。こうすることで、正しいアカウントを使って、リポジトリ データにアクセスして GitHub.com に書き込むことができるようになります。
-
ターミナルを開きます。
-
資格情報マネージャーを使用していることを確認するには、次のコマンドを入力し、出力をメモします。
Shell git config --get credential.helper
git config --get credential.helper
-
出力で資格情報マネージャーを使用していることが確認された場合は、資格情報マネージャーの保存された資格情報をクリアします。
- 出力に資格情報マネージャーの名前が含まれていない場合は、資格情報マネージャーが構成されていないため、次の手順に進むことができます。
- 出力が
manager
(前のバージョンではmanager-core
) の場合は、Git Credential Manager を使用しています。 資格情報をクリアするには、次のコマンドを実行します。
Shell echo "protocol=https\nhost=github.com" | git credential-manager erase
echo "protocol=https\nhost=github.com" | git credential-manager erase
-
GitHub でアクセスする各リポジトリの完全なリモート URL の資格情報をキャッシュするように Git を構成するには、次のコマンドを入力します。
Shell git config --global credential.https://github.com.useHttpPath true
git config --global credential.https://github.com.useHttpPath true
-
アカウントごとに
repo
スコープを持つ専用の personal access token (classic) を作成します。 または、アカウントごと、自分がメンバーになっている organization ごとに、目的のリポジトリへのアクセスが可能で、リポジトリの内容に対する読み取りと書き込みのアクセス許可を持っている fine-grained personal access token を作成します。 詳しくは、「個人用アクセス トークンを管理する」をご覧ください。 -
Git を使用してリポジトリをクローンしたり、既にクローンしたリポジトリ内のデータにアクセスしたりすると、Git によって資格情報が要求されます。 リポジトリに対してアクセス権を持つアカウントの personal access token を指定してください。
Git を使い、リポジトリのフル リモート URL に基づいてpersonal access tokenをキャッシュします。こうすることで、正しいアカウントを使って、リポジトリ データにアクセスして GitHub.com に書き込むことができるようになります。
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 SSH を使用した GitHub への接続.
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
Next steps
For reference information, see 個人用アカウントのリファレンス.