165

I would like to deploy a Heroku app which will be done ideally using git push -u heroku master. However this will only work if there are any pending commits to be pushed to master.

How can I redeploy the app while there is nothing to push ? I tried git push -u heroku master -f and still get the same below

Branch master set up to track remote branch master from heroku.
Everything up-to-date

PS: I also want to retain the existing app, which means I cannot make use of this answer https://stackoverflow.com/a/22043184/968442

Community
  • 1
  • 1
nehem
  • 12,775
  • 6
  • 58
  • 84
  • 4
    This sounds like an [XY problem](https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem). What do you hope to achieve by redeploying the same code again? – ChrisGPT was on strike Dec 27 '16 at 14:19
  • 1
    A case where I changed the few configvars, which deserves a redeployment but no commits – nehem Dec 27 '16 at 14:24
  • 1
    [Setting a config var](https://devcenter.heroku.com/articles/config-vars#setting-up-config-vars-for-a-deployed-application) causes your application to be restarted. It should take effect without needing to redeploy. Can you be more specific? – ChrisGPT was on strike Dec 27 '16 at 14:27
  • 3
    Unfortunately the configvar that I removed was `DISABLE_COLLECTSTATIC=1`, Which is supposed to invoke another Django command `manage.py collectstatic` which is hooked into heroku deployment logic. – nehem Dec 27 '16 at 14:32
  • In my case, I updated a git submodule which doesn't trigger a restart – ToonAlfrink Apr 14 '22 at 13:27

7 Answers7

242

Normally setting a config var causes your application to be restarted. In most situations there should be no need to redeploy after doing this.

If you really do need to trigger a new deployment you can add a new empty commit, then push to Heroku again:

git commit --allow-empty -m "Trigger Heroku deploy after enabling collectstatic"
git push heroku master

The new empty commit is a regular commit. It has a hash, an author, a timestamp, etc. It will have the same tree as its parent. This should cause Heroku to build your app slug again using the same code as the previous commit.

It's a bit awkward, but it works.

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
  • Sounds fair enough and does the job. Now I get tempted to backup/restore the repository(`.git`) to hide this commit from github. – nehem Dec 27 '16 at 15:06
  • @itsneo, I wouldn't bother. It's an ugly commit, but if you keep writing code on top of the previous commit you'll have to force push to Heroku the next time. That's not a great habit to get into, although it can be necessary sometimes… – ChrisGPT was on strike Dec 27 '16 at 16:39
  • 3
    Even with `git commit --allow-empty` I am receiving `Everything up-to-date` from Heroku... – Benny Code Sep 12 '17 at 21:39
  • @BennyNeugebauer, please look at your `git log`. Did you successfully create a new commit before pushing? – ChrisGPT was on strike Sep 12 '17 at 22:10
  • 5
    Ah, I see the issue! I was in a different local branch (than `master`). So I had to execute: `git push -f heroku the_branch_i_changed:master`. – Benny Code Sep 12 '17 at 22:18
  • 2
    just do `git commit --amend; git push heroku master -f` without actual changes, unless you have strict rules about rewriting public branch history. – Dmitry Mugtasimov May 22 '19 at 19:59
  • 2
    My JS assets are built during the deploy process, and they rely on ENV vars. So even if my app is restarted when I set an ENV var, my JS won't get rebuilt unless I do a deploy. ...just pointing this out cuz there are legit scenarios where one would want to redeploy – tybro0103 Oct 26 '19 at 15:21
76

You can do it from UI as well!

  1. Login to your Heroku dashboard and go to deploy section
  2. Find Manual deploy option

Hit Deploy Branch button!

enter image description here

Note: you must have your app connected to GitHub for this option to be available (see comment from Derek below).

ludovico
  • 2,103
  • 1
  • 13
  • 32
Hardik Raval
  • 3,406
  • 1
  • 26
  • 28
  • 34
    It's worth noting that you must have your app connected to GitHub for this option to be available. If you're using the Heroku Git deployment method without having connected the app to its GitHub repo, it's not immediately obvious how to deploy manually. – Derek Oct 22 '20 at 12:51
  • Agreed, but it is reasonable, heroku dashboard, click the deploy tab, click the connect to github button, type in your github repo in the search field, confirm and you are connected. I believe when connected it auto deploys on push. – jasonleonhard Jan 27 '21 at 21:54
  • Using Heroku Git deployment you need to rename `master` branch to `main` branch to allow deploy manually – ta2-1 Jan 03 '22 at 21:36
15

There is now also a plugin for the Heroku command-line that allows you to re-release the most recently deployed slug.

See https://www.npmjs.com/package/heroku-releases-retry

richard
  • 1,565
  • 2
  • 18
  • 35
  • 1
    At first I thought this is the solution, but actually it does only redploy but not rebuild. But there is a way to also rebuild without tainting you Git history by pushing a new commit: https://stackoverflow.com/q/9713183/322863 – aef Apr 28 '20 at 12:34
  • What is Python projects to do with npm ? – nehem Feb 13 '22 at 18:07
  • @nehem The npm package is a script to deploy a code package on Heroku. It has nothing to do with the type of project, whether Python or anything else. Its effectively the equivalent of a shell script – richard Jul 24 '23 at 23:46
13

It turns out there is a neat plugin for Heroku called heroku release retry that lets you retry the last deploy without resorting to adding bad commits to your repository.

// install plugin
heroku plugins:install heroku-releases-retry
// retry release
heroku releases:retry --app {your-app}

Source: https://www.darraghoriordan.com/2019/03/02/heroku-push-failed-force-rebuild

Henry Ruhs
  • 1,533
  • 1
  • 20
  • 32
4

You can run heroku restart --app app_name and you are good to go.

Leandro
  • 1,244
  • 16
  • 28
  • 18
    This doesn't rebuild the app, it only restarts it – PanMan Aug 21 '20 at 15:32
  • @PanMan The question says "How can I redeploy the app while there is nothing to push ?". It's not asking for the app to rebuild but to restart, and given that there were no changes I don't see why you would want to anyway. – Leandro Nov 06 '20 at 21:30
  • 5
    It clearly says "redeploy" not "restart." I, for instance, need to redeploy (not restart), because I am trying to Dockerize my app with Heroku, and as I'm debugging, I don't want to potentially pollute my git tree. It's how I ended up on this SO question. – Mike K Nov 17 '20 at 07:35
1

This worked for me, it did an actual build and release without any commit, contrary to one other post that only does a release:

heroku plugins:install heroku-builds
heroku builds:create --source-url https://user:token@api.github.com/repos/<username>/<repo name>/tarball/master/ --app <app-name>

Source: https://help.heroku.com/I3E6QPQN/how-do-i-force-a-new-deploy-without-adding-a-commit-to-my-github-repo

Hakim Bawa
  • 29
  • 3
-5

For stop the heroku app uses :

$ heroku ps:scale web=0

And for start it uses :

$ heroku ps:scale web=1
Dharmik Patel
  • 1,041
  • 6
  • 12
Umesh
  • 1