LoginSignup
5
6

More than 5 years have passed since last update.

リモートリポジトリに無理矢理プッシュする方法

Posted at

事象

Gitでcommitしたりresetしたり、いろいろしてからgit push herokuしたらエラー発生。

To https://git.heroku.com/***.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://git.heroku.com/***.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.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

違うんだ、ごちゃごちゃ操作してしまっただけで、僕のカレントブランチは決してビハインドじゃない。

解決策

git push heroku --forcegit push heroku -fでも可)で強制的にプッシュ。
これで一件落着。

注意

と思ったけど、調べてみると、--forceするのはあまりよくないらしい。

今回はRailsチュートリアルをやっていただけなので問題ないけど、複数人で開発する際は、--force-with-leaseを使った方がいいらしい。
ただし、注意も必要。

結論

  • 怒られたら理由を考える。
  • よくわかっていないコマンド(オプション)を使わない。
5
6
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
5
6