There are two concepts at play when adding a user friendly heroku name to a git repos.
There is the remote (git) and the app (heroku).
Git remotes are just aliases for git repositories. You can see what alias are currently setup for your git repos by typing:
> git remote -v
heroku email@example.com:.git (fetch)
heroku firstname.lastname@example.org:.git (push)
origin email@example.com:/.git (fetch)
origin firstname.lastname@example.org:/.git (push)
origin and heroku are the remotes – and their corresponding git repos.
origin is my git hub repos.
heroku is my remote name for my heroku git repos.
When I type:
> git push heroku
It pushes my code to the heroku git repos using the ‘heroku’ git remote name.
When you create an instance of your code base on Heroku, it gives your app a name. You can see your app names by typing:
> heroku apps
=== My Apps
And you can get more info (like it’s git url) by typing:
> heroku info -a secret-waters-xxxx
Git URL: email@example.com:secret-waters-xxxx.git
Owner Email: firstname.lastname@example.org
Repo Size: 7M
Slug Size: 33M
Web URL: http://secret-waters-xxxx.herokuapp.com/
What we want to do is tie these things together.
Tying a remote to an app
Say I created a staging environment, and I want to replace the heroku generated name it gave me (like secret-water) with a nicer name like ‘staging’. Here is how I would do it.
> git remote add staging email@example.com:secret-waters-xxxx.git
Now when I list my apps I should see staging there:
> git remote -v
staging firstname.lastname@example.org:secret-waters-xxxx.git (fetch)
staging email@example.com:secret-waters-xxxx.git (push)
And I should be able to push to my staging environment with this:
> git push staging
If you make a mistake you can remove a remote with
> git remote rm staging
For more examples of these and other commands feel free to checkout my heroku cheat sheet: