4
5

More than 1 year has passed since last update.

error: src refspec main does not match any が出た時

Posted at

状況

リモートリポジトリとローカルの紐付けが完了し、いざプッシュしようとした際に以下のエラーが出た。

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

解決方法

以下の記事を参考にさせていただきました。
https://deepblue-ts.co.jp/git/git-push-error/

原因は、プッシュしたいリモートリポジトリのブランチ名と、プッシュしようとしているローカルのブランチ名が異っているからだった。

実際に git branch で確認してみると

$ git branch
* master

masterのままで修正していないことが判明
(今回プッシュしたいリモートリポジトリは master ではなく main で設定している)

なので、以下のコマンドで mastermain に変更し、

$ git branch -m master main
$ git branch
* main

main に変わったことを確認し、再度プッシュをすればOK

4
5
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
4
5