LoginSignup
0
0

GitHub「fatal: The current branch main has no upstream branch.」

Posted at

エラー内容

  • git pushした際に起きた
fatal: The current branch main has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin main

To have this happen automatically for branches without a tracking
upstream, see 'push.autoSetupRemote' in 'git help config'.

エラー理由

  • ローカルの main ブランチがどのリモートブランチに対応するかが指定されていないため、git pushした際にどこにプッシュすればいいか分からずエラーとなった

解決方法

  • リモートブランチを設定すればOK
  • エラーメッセージにも記載されている通り、以下のコマンドを実行することで、main ブランチをリモートの origin に設定し、プッシュできるようになる
git push --set-upstream origin main

リモートブランチの設定を自動化するには?

  • 今後新しいブランチを作成した際に自動的にリモートブランチを設定したい場合は、push.autoSetupRemote 設定を有効にするとよい
git config --global push.autoSetupRemote true
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