現象
1.GitHubサイト上で空のリポジトリを作成した。
2.リモートリポジトリを追加した。
$ git remote add origin https://github.com/ユーザー名/○○○.git
3.上記で作成したリポジトリにpushを行ったが、エラーとなった。
$ git push origin <リポジトリ>
remote: Invalid username or password.
fatal: Authentication failed for 'https://github.com/ユーザー名/○○○.git/'
解決策
1.ユーザー名とメールアドレスの設定を忘れていた。
$ git config --global user.name <ユーザー名>
$ git config --global user.email <メールアドレス>
2.もう一度pushを行ったがエラーとなった。
$ git push origin <リポジトリ>
remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/ユーザー名/○○○.git/'
3.GitHubでアクセストークンを発行した。
- GitHubのユーザーアイコンから設定を開く。
- 左最下の開発者設定を開く。
- 個人アクセストークンを開く。
- repo/admin:repo_hook/delete_repoにチェックをいれてトークンを発行する。
- 発行したトークをメモる。
4.プッシュに成功。
- プッシュ時に問われるgithubのユーザー名とパスワードのうちパスワードは先ほど発行したトークを使用した。