久々にgithubを使ったら、IDパスワードは廃止、sshも非推奨、Personal Access Tokenを使え!と言われた。時の流れを感じる…。
githubに、新しいレポジトリmy-projectを作っておく
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# プロジェクトのフォルダを作成 mkdir my-project cd my-project # Gitの初期化 git init # GitHubのリポジトリに接続 git remote add origin https://github.com/【あなたのGitHubユーザー名】/my-project.git # 最初のファイルを作る echo "# My AWS Project" > README.md # 最初のコミット & プッシュ git add . git commit -m "Initial commit" git branch -M main git push -u origin main # エラーになって、プッシュ出来ない! remote: Invalid username or password. fatal: Authentication failed for 'https://github.com/【あなたのGitHubユーザー名】/my-project.git/' |
Personal Access Token (PAT) を発行する
https://github.com/settings/tokens
「Generate new token (classic)」 をクリック
「Note」に GitHub CLI Access と入力
「Expiration」(有効期限)を設定(No expiration でもOK)
「Select scopes(権限)」で以下を選択
✅ repo (リポジトリへのアクセス)
「Generate token」をクリック
発行されたトークンをコピー(超重要!)
⚠️ このトークンは一度しか表示されないので、必ずコピーしてメモしておく!
1 2 3 4 5 |
# Personal Access Token (PAT)を聞いてくるので入力すればプッシュ出来る! git push -u origin main # PAT保存も出来る git config --global credential.helper store |