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

This error is encountered when pushing to a remote repository.

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

Or you may get an error message like the following

$ 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.

If you do not resolve these errors, you will not be able to push to the remote repository.

In this article, we will show you how to solve the errors and the causes.

目次

Uncommitted

The following error is displayed due to a remote push that has not been committed.

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

The solution is to make a commit and then push.

The solution to this error is simply to commit.

You can push your changes to the remote repository after you have committed them.

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

The remote repository has the latest version

The following error is caused by the fact that there is a remote repository with the latest version that has not been pulled yet.

$ 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.

The solution is to pull the latest version in the remote repository and then push.

To solve this error, you need to pull the latest version of the source in the remote repository.

If you have changed the local sources, please follow the steps below to pull them and then push them.

  1. Commit the changes
  2. Pull the latest version in the remote repository
  3. Merge and push

You can perform the above steps with the following command.
If you pull the latest version of the remote repository after committing your changes, it will be automatically merged.

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

コメント

コメントする


reCaptcha の認証期間が終了しました。ページを再読み込みしてください。

目次