GitHubで途中でアカウントの2FAを有効にした場合、今まで使っていたリポジトリで git push origin xxx
を実行すると、
remote: Invalid username or password. fatal: Authentication failed for 'https://github.com/hoge/some-repo.git/'
とか、
fatal: unable to access 'https://github.com/hoge/some-repo.git/': The requested URL returned error: 403
といったエラーに遭遇します。
その時の対応法です。
解決法
- 新しくPersonal access tokensを発行する
.git/config
に記載されているurl
をhttps://{account name}@github.com/hoge/some-repo.git
の形式にする- 初回push時にパスワードを聞かれるので、1.で発行したPersonal access tokenを入力(ペースト)する