ときたの技術ノート

アウトプット!!!近道はない。泥臭く頑張れ。

【トークンの設定】git pushができない

はじめに

git pushができなくなると、毎度調べての繰り返しになっているので備忘録。

エラーメッセージ内容

https://docs.github.com/ja/enterprise-cloud@latest/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#creating-a-token
git push origin main
Username for 'https://github.com': <<USERNAME>>
Password for 'https://<<USERNAME>>@github.com':
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/<<USERNAME>>/TIL.git/'

やったこと

  1. git pushをしようとしたところ、ユーザー名とパスワードの入力を求められる。
  2. githubのアカウントパスワードを入力しても認証が通らない。
  3. アクセストークンを作成するも、認証が通らない。
  4. アクセストークンを権限を設定した上で作成。 ←これで認証が通る

解決方法

公式ドキュメントを参照し、アクセストークンの設定を行う。

docs.github.com

手順メモ

  1. 左側のサイドバーで [ Settings] をクリック。

  2. 左側のサイドバーの [ Personal access token] の下にある [Fine-grained トークン] をクリック。

  3. [General new token] をクリック。 新しいトークンの生成を行う。

  4. トークンの名前を入力。

  5. トークンの有効期限を選択。 (30days, 60days, 90days, custome と選択できる)

  6. [リソース所有者] で、リソース所有者を選択。 デフォルトでは、自分のgithubアカウントが設定されているので設定はこのままにしておいた。

  7. [Repository access]でリポジトリの選択。 自分の場合は、個人開発用で使うだけなので[All repositories]を選択。

  8. [Permissions] トークンに付与するアクセス許可を設定。

  9. [Generate token] をクリック。

です。以上!