I find myself doing this all the time, so I wanted to make note of the snippet here for anyone else commonly looking to add a Git remote for an existing Heroku app using the Heroku CLI. Open up your Terminal and enter the following commands to quickly link an existing Git project with one of your Heroku app’s.

Find Your Heroku Project Name

heroku list

This is display a list of all the Heroku projects you currently have, make sure you see the app name that you want to link with your git repo here.

Add The Git Remote

heroku git:remote -a PROJECT_NAME -r heroku

The -a parameter defines the name of your project, e.g. PROJECT_NAME, and the -r parameter defines the name of the git remote you want to use. The default value for the -r parameter is heroku.

That’s it! You can now push to heroku using the newly added remote.

About the Author

Kevin Leary is a freelance web developer in Boston, MA specializing in enterprise WordPress development, conversion optimization and JavaScript development.