LoginSignup
1
0

【Heroku】 error: failed to push some refs to "URL"が治らない....

Last updated at Posted at 2022-02-09

#Herokuを用いたデプロイ時のエラー原因が、「メインブランチ以外で作業を行なっていたこと」だった件

チーム開発でGithubを用いながらWebアプリケーションの開発を行なっていた時に行き詰まってしまったエラーを共有します

###状況
Ruby on Railsで作成したアプリケーションをherokuにデプロイしたい!!

terminal
voclabs:~/environment/railsアプリ名 (testbranch) $ git push heroku main

Herokuを用いてRailsのアプリケーションをデプロイするときに何回やっても下記のようなエラーが出てしまう

terminal
 ! [rejected]        main -> main (non-fast-forward)
error: failed to push some refs to 'URL'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and integrate the remote changes
hint: (e.g. 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

###環境

Cloud9(Amazon Web Service)
Rails 5.2.6
ruby 2.6.3p62 (2019-04-16 revision 67580)

###試してみたこと

errorと表示されている「error: failed to push some refs to 'URL'」について色々調べてみた。
しかしながら調べて出てくるコマンドを実行してみても治らなかった。

原因

自分が現在作業しているブランチが原因だったことがわかりました。
自分はずっと頑張って変更してもいないmainブランチをherokuにデプロイしようとしていたのです...泣
下記の記述方法だとマスターまたはメインブランチ​から heroku​ リモートにコードをデプロイしようとするみたいです。

terminal
voclabs:~/environment/railsアプリ名 (testbranch) $ git push heroku main

解決方法

ローカルリポジトリの非 main​ ブランチ (testbranch​ など) から Heroku にコードをデプロイする場合、次の構文を使用して、リモートの main​ ブランチにプッシュされるようにすること

terminal
voclabs:~/environment/railsアプリ名 (testbranch) $ git push heroku testbranch:main

上記の「testbranch」は現在自分が作業し、commitなどを行なっているブランチ名を指定しましょう

###参考元
https://devcenter.heroku.com/ja/articles/git

###最後に

ここまで読んでくだりありがとうございます。
拙い文章で申し訳ないのですが、自分のエラー解決方法が誰かのためになればと思います。

1
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
1
0