LoginSignup
0
0

More than 3 years have passed since last update.

cloud9環境でgithubの初回pushができなかった話

Posted at

エラー内容

・cloud9でenvironmentsを作成。
・作成時にUbuntuを選択。
・rails newでrailsアプリケーションを作成
・git関連の以下を実行

$ git add -A

$ git commit -m "xxx"

$ git remote add origin "xxx(github上のリポジトリURL)"

$ git push -u origin main

error: src refspec main does not match any.
error: failed to push some refs to 'https://github.com/xxx/xxx.git'

このエラーでしばらく引っかかった。

解決策

ローカルリポジトリのブランチ名をmasterからmainへ変更してからpushすると解決。

なぜか??

https://www.publickey1.jp/blog/20/githubmainmastermain.html
最近、githubのデフォルトブランチが「main」に変更されている。

だがcloud9でローカルリポジトリを作成(git init)するとブランチ名は(master)になっているため、エラーがでていた。

 
 

$ git push アップロード先のリモートリポジトリ名 ローカルブランチ名
$ git push -u origin main

Gitは上流リポジトリ(この場合GitHub上のリモートリポジトリ)のうち指定がなければ同名のブランチにプッシュするようです。 もし同名ブランチがなければ勝手にリモートリポジトリに作成されます。

この

$ git push origin main

はorigin(github上のリポジトリ名)にローカルブランチ(main)をpushするよ!

という意味だけど、そもそもcloud9上でのブランチは「master」なので「mainなんてローカルブランチないよ」とエラーを返されていただけでした。

試してないが、おそらく

$ git push origin master

にしていたらエラーはでず、github上に「main」と「master」の2つのブランチが作成されていたと思われる。

git,githubの基本がわかっていなかったことが原因でした。

0
0
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
0
0