Skip to content

Instantly share code, notes, and snippets.

@NathBabs
Forked from nabucosound/heroku_env_copy.sh
Created September 21, 2021 20:55
Show Gist options
  • Save NathBabs/5d01049df10373614d01fb623c64604f to your computer and use it in GitHub Desktop.
Save NathBabs/5d01049df10373614d01fb623c64604f to your computer and use it in GitHub Desktop.
Script to copy environment variables from an existing heroku app to another one
#!/bin/bash
# Source: http://blog.nonuby.com/blog/2012/07/05/copying-env-vars-from-one-heroku-app-to-another/
set -e
sourceApp="$1"
targetApp="$2"
while read key value; do
key=${key%%:}
echo "Setting $key=$value"
heroku config:set "$key=$value" --app "$targetApp"
done < <(heroku config --app "$sourceApp" | sed -e '1d')
@NathBabs
Copy link
Author

NathBabs commented Sep 21, 2021

FYI much quicker to set them all in one heroku config:set a=b c=d etc

If you prefer a manual review and you do have bash/zsh:

heroku config -s -a source-heroku-app > config.txt

Now review config.txt and remove any unwanted config lines

cat config.txt | tr '\n' ' ' | xargs heroku config:set -a target-heroku-app

https://gist.github.com/nabucosound/8181671#gistcomment-2597319

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment