error: Couldn't resolve host 'github.com' while accessing https://github.com/... (´゚д゚`)エー!
◯ 事象
gitで新規リポジトリをつくったので、
localにあるものをpushしようとしたらエラった。
$ git remote add origin https://github.com/****/rails_first_app.git $ git push -u origin master error: Couldn't resolve host 'github.com' while accessing https://github.com/****/rails_first_app.git/info/refs fatal: HTTP request failed
◯ 状況把握
$ git remote -v origin https://github.com/mokokko/rails_first_app.git (fetch) origin https://github.com/mokokko/rails_first_app.git (push)
=> git clone等はできるが、git pushができない
◯ 解消方法
git remote に設定したurlをSSLではなくSSH経由に変更する。
- リポジトリの設定を直接変更する
$ git remote set-url origin <SSH経由のurlを記載>
or
- .gitconfigの設定を追加する
[url "git@github.com:"] pushInsteadOf = git://github.com/ pushInsteadOf = https://github.com/ [url "git://github.com/"] # こっちはついで insteadOf = https://github.com/
設定 | 設定内容 |
---|---|
[url "git@github.com:"] pushInsteadOf | URL の指定として https: や git: を使っていても git push のときには ssh 経由にする |
[url "git://github.com/"] insteadOf | git fetch や git pull の時は https: の代わりに git: を使う |
.gitconfigの設定をするとこうなる↓
[before: 設定前] $ git remote -v origin https://github.com/mokokko/rails_first_app.git (fetch) origin https://github.com/mokokko/rails_first_app.git (push) [after: 設定後] $ git remote -v origin git://github.com/mokokko/rails_first_app.git (fetch) origin git@github.com:mokokko/rails_first_app.git (push)
e-mailとかuser.nameの設定があーだこーだだったり
証明書が古いんじゃないか説とかもあるが、
とりあえずこれで解決する。