error: failed to push some refs to ‘REMOTE URL’

このエラーはリモートリポジトリにpushする時に遭遇するエラーです。

$ git push -u origin main
error: src refspec main does not match any
error: failed to push some refs to 'REMOTE URL'

または次のようにエラーが表示されることもあります。

$ git push -u origin main
error: failed to push some refs to 'REMOTE URL'

hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

これらのエラーを解決しないとリモートリポジトリにpushできません。

この記事ではエラーの解決方法と原因をご紹介します。

目次

コミットされていない

次のエラーは、commitされていない状態でリモートにpushしたことが原因で表示されるエラーです。

$ git push -u origin main
error: src refspec main does not match any
error: failed to push some refs to 'REMOTE URL'

解決方法はコミットをしたあとにpushをする

このエラーの解決方法は単純にコミットをするだけです。

変更したものをcommitした後にリモートリポジトリにpushできます。

$ git add .
$ git commit
[(root-commit) 96d2709] comment
...
$ git push origin [branch]
Enumerating objects: 6, done.
Counting objects: 100% (6/6), done.
...

リモートリポジトリに最新版がある

次のエラーは、まだpullされていない最新版がリモートリポジトリあることが原因で表示されるエラーです。

$ git push -u origin main
error: failed to push some refs to 'REMOTE URL'

hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

解決方法はリモートリポジトリの最新版をpullした後にpushをする

このエラーを解決するには、リモートリポジトリにある最新版のソースをpullする必要があります。

ローカルのソースを変更した場合は次の手順でpullした後にpushをしてください。

  1. 変更をcommitする
  2. リモートリポジトににある最新版をpullする
  3. マージしてpushする

次のコマンドで上記の手順を行えます。
変更をコミット後にリモートリポジトリの最新版をプルすると自動的にmergeされます。

$ git add .
$ git commit
$ git pull origin [branch]
$ git push origin [branch]
よかったらシェアしてね!
  • URLをコピーしました!
  • URLをコピーしました!

コメント

コメントする


The reCAPTCHA verification period has expired. Please reload the page.

目次