LoginSignup
2
2

More than 3 years have passed since last update.

git pushで自分のレポジトリへのアクセスが403で拒否される対処法 Remote: Permission to user1/repo denied to user2

Posted at

windows PCで自分のレポジトリへgit pushしたら403エラーが返ってきた際の対処法

githubのアカウントを2つ持っているが、pushした際にクローンしたレポジトリと違う方のユーザーが認識されてしまい、403エラーが返ってきた。

remote: Permission to user1/demo-repo.git denied to user2.
fatal: unable to access ‘https://github.com/user1/demo-repo.git/’: The requested URL returned error: 403code

ちなみにここでは以下の環境を使用している

・Windows 10 PC
・git bash 2.26

まずはgitconfigを確認した

$ cat ~/.gitconfig
[user]
    name = user1
    email = user1@gmail.com

アクセスしたいレポジトリのユーザーになっているから問題はなさそう...
ちなみにユーザーが違う場合、あるいは登録されていない場合は以下2つのやり方で登録する。

1.直接configファイルを編集する

$ vi ~/.gitconfig 

2.コマンドラインで登録する

$ git config --global user.name "user1"
$ git config --global user.email "user1@gmail.com"

もう一度pushしてみる

$ git push origin master

同じエラーがでる...
再インストールも試してみたが、エラーは治らず。

そこでPC側がどのように認証をしているのか確認した

$ git config credential-helper
manager

調べてみるとPC側の資格情報マネージャーによってユーザーを認証しているようだ。
認証情報を一度消すことによって解決できるそうだ!
コントロールパネル>(ユーザーアカウント)>資格情報マネージャー>Windows資格情報

githubの資格情報があったらそれを削除する。
image.png

もう一度pushしてみる。

$ git push origin master

するとusernameとpasswordを聞かれる画面がポップアップで出てきた。
image.png

この画面にクローンしたレポジトリのユーザー名を入れることで解決できた!

ちなみにMacを使用している方はkeychain managerに資格情報があるようなので、そこでgithubの資格情報を削除することで対処できるようだ。

以下サイトを参考
https://www.freecodecamp.org/forum/t/need-your-help-with-github-permission-denied-to-my-own-repo/17421/4

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