You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Heroku CLI技术疑问:heroku config如何识别目标应用?

How Heroku CLI Determines Which App to Target for heroku config Commands

Great question! You're spot-on that the local directory name alone doesn't tell Heroku which app to interact with. Let me break down the key ways the CLI figures out which server-side app to target:

  • Git Remote Configuration
    This is the primary method. When you first deploy an app via heroku create or link a local repo to an existing Heroku app with heroku git:remote -a <app-name>, Heroku adds a Git remote named heroku to your local repository. This remote points directly to your app's Heroku Git URL (e.g., https://git.heroku.com/your-app-name.git). The CLI checks this remote entry to map your local directory to the correct server app. If your second local directory doesn't have this remote set up, the CLI has no way to know which app you're referring to.

  • Local .git/config File
    The remote details are stored in your repo's .git/config file. You can verify this by running cat .git/config in your working directory—look for a section like this:

    [remote "heroku"]
      url = https://git.heroku.com/your-app-name.git
      fetch = +refs/heads/*:refs/remotes/heroku/*
    

    If this section is missing in your second directory, that's exactly why heroku config fails to run properly there.

  • Explicit App Flag
    You can always bypass automatic detection by specifying the app directly using the -a or --app flag. For example:

    heroku config -a your-app-name
    

    This is handy if you have multiple local repos for the same Heroku app, or if you want to run commands without being in the app's local directory.

  • Default App Context (Less Common)
    If you're using Heroku Teams or manage multiple apps, you might have set a default app via heroku apps:default <app-name>. The CLI will use this default if no Git remote is found and no app is specified explicitly.

Quick Fix for Your Second Directory

To get heroku config working in your second local folder, just run this command from within that directory:

heroku git:remote -a your-app-name

This adds the required Heroku Git remote, and the CLI will then correctly map the directory to your server-side app.

内容的提问来源于stack exchange,提问作者Michel

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 03:34:31