事例
・git hubにてリモートリポジトリ作成済み。
・ローカル環境でgit add
、git commit
等使用しながらバージョン管理。
・一通り完了したのでgit push origin master
を実行したところ下記エラーが発生。
% git push origin master
error: src refspec master does not match any
error: failed to push some refs to 'リポジトリパス'
解決法
git push origin master
を下記に変更
git push origin main
原因
・以前は「master」ブランチが自動作成されていたが、2020/10以降新規レポジトリを作成すると「main」ブランチが作成されるため。
→作成しているレポジトリがgit push origin master
なのか、git push origin main
なのか気をつける必要あり。
ところで「ブランチ」とは
履歴の流れを分岐して記録していくための機能。
この機能を使うことで、他のメンバーと分担して作業を行うことができ、合流(マージ)することで1つのブランチにまとめることができる。
今回の「masterブランチ」について
・最初のコミットで生成されるブランチで、要するに主軸となるブランチ。
・個人で開発している場合など、ブランチを分岐させない場合、masterに対してpushすることになる。
※この名称が2021/10以降「main」に変更
参考
git push時のerror: src refspec master does not match anyについて
サル先生のGit入門