228
171

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

git push 時の error: failed to push some refs to

Last updated at Posted at 2017-11-20

経緯

過去にgithubにpushしたbranchで、  masterが更新されたためgit rebase を行った後に再度remoteのgithubにpushしようとしたらこのエラーがでてしまいました。

$ git push origin branch-name
To github:team_repository/repository_name.git
 ! [rejected]        branch_name -> branch_name (non-fast-forward)
error: failed to push some refs to 'github:team_repository/repository_name.git'
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.

原因

過去に一度remoteにpushした場所との整合性がとれずerrorがでてしまったらしいです。

解決法

この解決法は現在のローカルブランチが100%正しい場合のみになるのですが、

git push origin :branch-name
git push origin branch-name

で直ります。

git push origin :branch-name
はremoteのブランチを一旦deleteするという意味です。
一旦過去の大昔にpushしていたブランチを排除し、新しいブランチとしてまた作り直すということですね!

twitterもフォローよろしくおねがいします。 !

228
171
4

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
228
171

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?