LoginSignup
8
9

More than 5 years have passed since last update.

githubでリモートへの初回pushでよく手間取る

Last updated at Posted at 2018-05-13

概要

久々にリポジトリを作った時に、あれ、前どうやってpushの設定したっけ。。。となるのでメモ。

本題

自分のなかで よく遭遇するうまくいかないポイントはちゃんとリモートを追加できていないこと。以下のコマンドを実行すればリモートが表示されるのだが、表示されない。

git remote -v

表示されないなら、設定されていないってことだよね、じゃあgit remote addでリモートの設定をすれば良いじゃん?と安直な考えから、以下のことをするとエラーが出てしまってうまく設定できない。

$ git remote add origin https://github.com/[アカウント名]/[レポジトリ名].git
> fatal: remote origin already exists. <-こんなこと言われる

この際に、addではなくset-urlにするとリモートを追加することができる。

$ git remote set-url origin https://github.com/[アカウント名]/[レポジトリ名].git

この後にpushをすることでようやく初回pushができる。

git push -u origin master
8
9
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
8
9