2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

今更SourceTreeからGithubに繋いだときに認証エラーで詰まった話

Last updated at Posted at 2024-10-14

概要

久しぶりにSourceTreeからGitHubのリポジトリに変更をpushしようとした際、エラーが発生して少し詰まったので、備忘録的に解決方法を共有します。

解決方法まとめ

  • SourceTreeからGitHubに接続するためにPersonal Access Tokensが必要
  • SourceTreeのAdvanced設定から、事前にGitHubアカウント情報を削除
  • Personal Access Token発行時の推奨権限:
    • Contents:Read and write
    • Commit Statuses:Read and write
    • Pull Requests permissions:Read and write
    • Workflows permissions:Read and write

背景

SourceTreeからGitHubへのpushを試みた際に、認証エラーが発生し接続ができなくなりました。

  • SourceTree経由のpullは成功
  • コマンドライン上でのgit pushも正常
  • しかし、SourceTreeからのpushだけ失敗

原因

GitHubではセキュリティ向上のため、パスワードでの認証を廃止し、Personal Access Tokenの使用が必須になっているみたいです。(多分結構前から、、、)

Personal Access Tokenの発行時には適切な権限を設定する必要があります。

対応手順

1. 古い認証情報をSourceTreeから削除する。

SourceTree > Settings > Advancedから、GitHubのアカウント情報を削除します。

日本語設定の場合、「Advanced」ボタンが押せないことがあるため、その場合は言語を英語に変更します。

スクリーンショット 2024-10-14 13.22.21.png

2. Personal Access Tokens発行画面にアクセス

GithubのPersonal Access Tokens発行画面にアクセスし、Fine-grained TokensGenerate new tokenを選びます。

スクリーンショット 2024-10-14 13.28.59.png

3. Personal Access Tokensの権限を選択

Repository AccessAll repositoriesに設定します。
その後、Permission > Repository permissionsから下記の権限を選択します。

名前 レベル 概要
Contents Read and write git clone, git pull, git push に必要
Metadata Read-only リポジトリメタデータの取得に必要(git ls-remote など)
Pull requests Read and write プルリクの作成・操作に必要
Workflows permissions Read and write git pushでGitHub Actionsをトリガーする場合必要

スクリーンショット 2024-10-14 13.38.28.png
スクリーンショット 2024-10-14 13.39.00.png
スクリーンショット 2024-10-14 13.40.35.png
スクリーンショット 2024-10-14 13.40.58.png

3. 発行したトークンをSourceTreeに設定

SourceTreeでpushを行った際に、認証を求められるので、先ほど、発行したトークンで認証を行ってください。

スクリーンショット 2024-10-14 13.42.44.png

FAQ

git pull時に403エラーがでる。

権限設定がたりていません。

3. Personal Access Tokensの権限を選択を見直してください。

git pull時に400エラーがでる。

Personal access tokens (classic)を使っていた場合、400エラーがでる場合があります。

トークン発行時にTokens (classic)ではなく、Fine-grained Toknesを選択してください。

感想

エンジニア歴五年目でこんなところに躓くとは思わなかった、、、

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?