LoginSignup
139
106

More than 5 years have passed since last update.

gitでpushしようとしたら403された話

Posted at

新しくgitのアカウントを作り、ローカルでゴニョゴニョして、addしてcommitしてpushしたら↓のようなエラーが・・

$ git push origin master
error: The requested URL returned error: 403 Forbidden while accessing https://github.com/hogehoge/rss.git/info/refs

fatal: HTTP request failed

ここまでどうやったか

一応手順が間違ってなかったことを確認するために、
ここまでどうやって来たかをまとめて起きます。

A. githubでリポジトリ作成

最初にgithubでリポジトリを作りました。

B. ユーザ名登録

$ git config --global user.name "hogehoge"
$ git config --global user.email hogehoge@example.com

C. リポジトリの登録

$ git remote add https://github.com/hogehoge/rss.git
# 今回はrssという名前のリポジトリを作りました

D. sshキーの登録

(ローカルにて)
$ ssh-keygen -t rsa

これで、~/.ssh/id_rsa.pubをgithubに登録

E. いざPush!

$ git push origin master
error: The requested URL returned error: 403 Forbidden while accessing https://github.com/hogehoge/rss.git/info/refs

fatal: HTTP request failed

おぉ・・・

解決策

リモートのURLにユーザ名を含めてあげる必要があるそうです。

$ git remote set-url origin https://hogehoge@github.com/ritukiii/rss.git

これで、git configでremoteのURLが変わったことを確認して変わってればOK.

もう一度挑戦!!

pushしたらパスワード聞かれて無事に成功!

$ git push origin master
Password: 
Counting objects: 132, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (114/114), done.
Writing objects: 100% (132/132), 808.06 KiB, done.
Total 132 (delta 7), reused 0 (delta 0)
To https://hogehoge@github.com/ritukiii/rss.git
 * [new branch]      master -> master
139
106
5

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
139
106