githubに新規リポジトリに初めてのpushしようしたらThe requested URL returned error: 403となってしまった時の対処法をメモ。
pushできない時の現象
h2tomo:sample_app hogehoge$ git remote add origin https://github.com/hogehoge/sample_app.git h2tomo:sample_app hogehoge$ git push -u origin master remote: Permission to hogehoge/sample_app.git denied to hogehoge. fatal: unable to access 'https://github.com/hogehoge/sample_app.git/': The requested URL returned error: 403
解決策
下記のように太字箇所に自分のgithubのユーザー名を入れてgit remote set-url originとしてあげると問題なくpushできました。
git remote set-url origin https://hogehoge@github.com/hogehoge/sample_app.git
h2tomo:sample_app hogehoge$ git remote set-url origin https://hogehoge@github.com/hogehoge/sample_app.git h2tomo:sample_app hogehoge$ git push origin master Password for 'https://hogehoge@github.com': Counting objects: 84, done. Delta compression using up to 4 threads. Compressing objects: 100% (70/70), done. Writing objects: 100% (84/84), 20.37 KiB | 0 bytes/s, done. Total 84 (delta 2), reused 0 (delta 0) remote: Resolving deltas: 100% (2/2), done. To https://github.com/hogehoge/sample_app.git * [new branch] master -> master