46

I have more than one app/git remote at heroku and I would like to know if it is possible to configure a default application so that, whenever I forget to specify the app (--app), the toolbelt would use it.

danronmoon
  • 3,814
  • 5
  • 34
  • 56
Rafael Oliveira
  • 2,823
  • 4
  • 33
  • 50

3 Answers3

50

You can set the heroku.remote key in your repo's Git config to the name of the default remote. For example, if your remote is called staging, you could do this:

$ git config heroku.remote staging

To see how this works, here is the relevant source.

For more, information about this, see Managing Multiple Environments for an App.

ryanbrainard
  • 5,918
  • 35
  • 41
  • 2
    Answer with source, nice! If I could double vote, I would do it. – Rafael Oliveira Jul 09 '13 at 17:10
  • 13
    Am I misunderstanding what this should do? I was expecting this to allow me to use heroku toolbelt CLI without having to specify `--app`. It's not working for me: – denishaskin Jun 20 '14 at 17:13
  • 1
    @denishaskin Would you mind to paste `git remote -v` results? – Rafael Oliveira Jun 20 '14 at 18:13
  • this is an awesome solution – wlingke Aug 24 '15 at 17:20
  • 1
    The current Heroku CLI seems to set git remote name `heroku` as default (ref. https://devcenter.heroku.com/articles/git#for-a-new-heroku-app). So many users should set `heroku` instead of `staging` (i.e. `$ git config heroku.remote heroku`). The remote name can be checked by `$ git remote -v`. If the output is like this: `git-remote-name https://git.heroku.com/your-heroku-app-name.git`, you should type `$ git config heroku.remote git-remote-name`. – shuuji3 May 26 '18 at 15:19
  • @denishaskin I was having the same issue, and fixed it by running `git config heroku.remote heroku` and then `heroku git:remote -a ` – Nicholas Barry Mar 04 '19 at 15:59
44

You could also go for:

heroku git:remote -a <name-of-the-app>

or if you tend to make a lot of mistakes in the configuration of wrong apps, you can use this library I made: https://github.com/kubek2k/heroshell

This is a Heroku wrapper shell that allows you to work in the context of a given Heroku application

Samuel Liew
  • 76,741
  • 107
  • 159
  • 260
kubek2k
  • 5,613
  • 2
  • 22
  • 16
32

You can set the HEROKU_APP environment variable.

Found this question while searching for it myself. The other answers refer to Heroku's old ruby-based CLI. The new JS CLI doesn't seem to support the same git-remote-reading feature. A quick search of the source code on GitHub found this.

Fission Xuiptz
  • 321
  • 3
  • 4
  • This worked for me to set the default app for Heroku CLI in order to avoid specifying the -a or --app parameter in all commands. – Vichoko May 20 '22 at 15:01