Sourcetreeを使ってGitHubのリポジトリからクローンしようとした時に、次のようなエラーが出ることがあります。
remote: Write access to repository not granted.
fatal: unable to access 'https://github.com/konsuki2/trash-pickup-website.git/': The requested URL returned error: 403
クローンできないと困りますよね。解決していきましょう。
解決法:新しいトークンを作成する
トークンの作成
GitHubにログインした状態で、 GitHubのトップページを表示します。

その後、右上にあるアカウントのアイコンをクリックし、表示されるメニューからSettingsを選択します。

左側にあるメニューの中から、Developer settings を見つけてクリックします。

表示されるページの左側にあるメニューから、Personal access tokens > Tokens (classic) のように選択します。

Generate new token ▼ をクリックして、表示されるメニューからGenerate new token (classic)を選択します。

New personal access token (classic)の設定項目を見てください。

この部分を次のように設定します。
設定項目 | 設定内容 |
---|---|
Note | token20220102 |
Expiration | 30 days |
Select scopes | repoにチェック |
上に示した設定内容は、1つの例です。
ご自分に合った設定をしていただいても大丈夫です。
設定が完了したら、スクロールして一番下にある Generate token と書かれたボタンをクリックします。

すると、パスワードが表示されます。ページを移動してしまうと、もう1度確認することができなくなるため、このパスワードをコピーしておいてください。

Sourcetreeにおけるアカウントの設定
Sourcetreeを起動して、メニューから環境設定を開きます。

アカウントの項目を選択します。

GitHubのアカウントを選択して、編集を押します。

次のように設定します。
設定項目 | 設定内容 |
---|---|
認証タイプ | Basic |
ユーザー名 | GitHubのユーザー名 |
パスワード | トークンを作ったときにコピーしたパスワード |
プロトコル | HTTPS |
▼ こんな感じです。

ポイントは、パスワードの欄に先ほどコピーしたパスワードを貼り付ける点です。
GitHubのログイン時に入力するパスワードと間違えないように気をつけてください。
設定が完了したら<保存>ボタンを押します。

これで、Sourcetreeからクローンする際にエラーが発生しなくなると思います。
コメント