GitHubで複数のアカウントを使う
GitHubで複数のアカウントを使う場合は、ちょっと配慮が必要。
たとえば、このような場合。
プロジェクトA — https://github.com/userA/example-01.git
プロジェクトB — https://github.com/userB/sample-01.git
userA を普段使っていて、今回一部を userB にするとする。
Windowsの場合、資格情報マネージャーがアカウント情報を管理している。
https://github.com のアカウント情報には、userA のアカウント名と そのアクセストークンが保存されている。
この時、プロジェクトBをクローンするときに、アカウント名を指定して クローンする。
$ git clone https://userB@github.com/userB/sample-01.git
すると、資格情報マネージャーが起動するので、アクセストークンを入力して “Sign in” とする。
これで、クローンできる。
また、すでに作業フォルダが作成されていて、それに リモートリポジトリを 関連づけている場合は、以下のように修正する。
まず、現状。
$ git remote -v
origin https://github.com/userB/sample-01.git (fetch)
origin https://github.com/userB/sample-01.git (push)
このようになっているはずなので、
$ git remote rm origin
$ git remote add origin https://userB@github.com/userB/sample-01.git
この後、git push -u origin main とできる。
参考
[GitHub] httpsでremote: Repository not found.となった時の対応方法
カテゴリー: Git, memo
タグ: account, remote, username, 複数のアカウント
カウント: 233