0

Here is a question about the Heroku CLI.

When I run this command inside my local folder for a given app already on the server:

heroku config

I get a list of my environment variables settings.

But if I run the same command from another folder with the same name it does not work anymore.

This shows that the name of the local folder is not enough for heroku config to know which app I am thinking about.

How does heroku config know which app to query on the server?

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
Michel
  • 10,303
  • 17
  • 82
  • 179

1 Answers1

1

By default, Heroku infers the app from your Git remotes:

App commands are typically executed from within an app’s local git clone. The app name is automatically detected by scanning the git remotes for the current working copy, so you don’t have to specify which app to operate on explicitly.

You can also explicitly tell it what app to use:

If you have multiple heroku remotes or want to execute an app command outside of a local working copy, you can specify the remote name or an explicit app name as follows:

heroku apps:info --app example

heroku apps:info --remote production

Or via environment variable:

Alternatively, the app name can be specified by setting the HEROKU_APP environment variable.

Community
  • 1
  • 1
ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
  • Thanks for this kind reply. But this does not actually tell me what I want to know. The question is "How does it infers ... from the Git Remotes?". In the case of my post, it worked in one case and not the other one. Why? Is there some specific file or something making the difference? – Michel May 07 '18 at 02:22
  • @Michel, your question says that, "the name of the local folder is not enough for `heroku config` to know which app I am thinking about". It says nothing about Git remotes. In any case, I'm not sure what's unclear about my answer. The Heroku CLI inspects your Git remotes looking for one that points to a Heroku Git repository (something like `https://git.heroku.com/some-app.git`). If it finds exactly one such remote it uses it. – ChrisGPT was on strike May 07 '18 at 11:04
  • OK. I see that it inspects my Git remotes (as you point out). But how do you explain that it finds something when I run the command from one folder and not when I run it from the other one. I can only think that there is a local element giving some clue to the CLI. This is what I was trying to figure out.... Unless this element is precisely the https://...git you are referring to? If that is the case. Where is this located? – Michel May 09 '18 at 09:09
  • "But how do you explain that it finds something when I run the command from one folder and not when I run it from the other one. I can only think that there is a local element giving some clue to the CLI." Git remotes _are_ the local element. They are configured per-repository. Try running `git remote -v` in each of your folders. Configured remotes are saved in the repository's `.git/config` file. – ChrisGPT was on strike May 09 '18 at 12:10