LoginSignup
50
39

More than 5 years have passed since last update.

git pushで403のエラーが返ってくる問題

Posted at

はじめに

  • gitのpush時のエラーに関してです。
  • 自分はとある事情で二つ目のgithubアカウントを作成しました。
  • そのアカウントでリモートリポジトリを作成後cloneしてきてInitial commitしたあとにpushしようとしたら、、、まさかのエラーがでました。涙
remote: Permission to<username(new)>/<repositoryname>.git denied to <username(old)>.
fatal: unable to access 'https://github.com/<username(new)>/<repositoryname>.git/'
: The requested URL returned error: 403
  • 上記のようなエラーです。
  • 自分の考えとしては、ユーザ名とメールアドレスが間違っているのだと思いました。
  • globalに設定しているものを見てしまっていて、権限がないのだと思いました。
  • ですので、localの設定(.git/config)を変更してやろうと思いました。
git config --local user.name "username(new)"
git config --local user.email "email(new)"
  • 失敗
  • 次に調べるとどうやらグローバルの設定(~/.gitconfig)を見てしまっているような気がしました。
  • しかし、グローバルの設定を設定し直しても変わりませんでした。。涙

解決方法

  • 解決方法した方法は、リモートのURLにユーザ名を入れることです。
  • 具体的にどういうことかというと
  • 普通のリモートのURL
https://github.com/<username>/<repositoryname>.git
  • ですが、これを変更します。
git remote set-url origin https://<username(new)>@github.com/<username(new)>/<repositoryname>.git
  • 上記のような感じです。
  • github.comの前に自分のユーザ名を入れて@で区切るといった感じです。
  • こんなやり方があったんですね、、知らなかった
  • これをやってからpushをすると、パスワードが求められます。
  • 正常なパスワードを入力すると無事にpushができました!!!
50
39
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
50
39