LoginSignup
14
17

More than 3 years have passed since last update.

Github 初push時のエラー ~ src refspec main does not main any

Posted at

githubで新しくプロジェクトを作成して、ローカルの物をpushしようとした時に遭遇するエラーの解決方法のメモです。

手順/エラー内容

githubで新しくプロジェクトを作成すると以下の表示が見つかります。

…or push an existing repository from the command line
git remote add origin git@github.com:.........
git branch -M main
git push -u origin main

従って実行すると、以下の様なエラーになってしまいます。

git branch -M main 時のエラー

$ git branch -M main
error: refname refs/heads/master not found
fatal: Branch rename failed

git push -u origin main 時のエラー

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

解決方法

git branch -M main 時のエラー

git checkout -b でブランチを作れます。

git checkout -b main

これでmainブランチに行けます。

git push -u origin main 時のエラー

git add して

git add .

コミットします。

git commit -m 'First Commit'

すると、無事にpushできる様になります。

参考資料

【Git】初プッシュ時にsrc refspec master does not match anyとエラーになる

14
17
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
14
17