0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

2アカウントによるgithubのPermission denied errorにハマった話

0
Last updated at Posted at 2025-11-25

本記事は、一部AIに推敲を協力してもらっています。

背景

学生用アカウントと個人用アカウントの2つのGitHubアカウントを使い分けています。

新規作成した個人用のリポジトリに対して push を行おうとしたところ、以下のエラーが多発し、操作できない現象が発生した。

Permission to [リポジトリ名] denied to [過去のアカウント名].

(同様の事例はWeb上に散見されるが、自身の備忘録として解決プロセスを詳細に記録させていただきます。)

TL;DR

原因は、Gitの認証補助設定(credential.helper)がシステムレベルで強制されていたことにあった。

  • 確認コマンド:git config --list credential.helper=osxkeychain
    が設定されていた。
  • 解決コマンド: git config --local credential.helper
    を実行し、一時的に設定を無効化することで解決。

原因究明のプロセス

1. 基本設定と接続確認

2つのアカウントを使い分ける特殊な環境であるため、まずは基本設定を疑った。

  • git config --local user.name 等の設定は正しい
  • HTTPS接続のURLの確認

しかし、設定が正しいにもかかわらず改善しなかったため、Gitの認証プロセスそのものを調査したところ、credential.helper という設定項目の存在にたどり着いた。

credential.helper
Gitがリモートリポジトリ(GitHub等)へアクセスする際、ユーザー名やパスワード(アクセストークン)を毎回入力しなくて済むように、認証情報をPC内に保存・自動入力してくれる補助機能のこと。

2. システム設定の干渉(osxkeychain)

設定状況を詳しく確認するため、以下のコマンドを実行した。

git config --show-origin --get-all credential.helper
file:/Applications/Xcode.app/Contents/Developer/usr/share/git-core/gitconfig        osxkeychain
file:.git/config  

これが原因ぽそうですね。
どうやらXcodeでは、初期設定でosxkeychainが設定されるそうで...
何度やっても元のメインアカウントが参照され続けるようです。

osxkeychain
macOS標準の「キーチェーンアクセス」というパスワード管理機能を使って、Gitの認証情報を保存する仕組み。

対処

以下のコマンドを実行:

git config --local credential.helper ""

結果、正しいアカウントのトークンを入力することができ、無事に push が成功した。

参考

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?