Here's a very clear explanation that is lacking from ther Heroku documentation or other answers to the question. At least all the info doesn't seem to appear in any one place. It also let's you understand the problem in a way that the accounts tool doesn't.
Heroku identifies you in 2 ways:
The first is in .git/config
[heroku]
account = acccount_name
This seems to let you perform basic operations using heroku
The second way heroku identifies you is by any operation that uses ssh (git push). Heroku will identify you by your ssh key, as stated here:
https://devcenter.heroku.com/articles/keys
This keypair is used for the strong cryptography and that uniquely
identifies you as a developer when pushing code changes.
So each heroku account that you work on will have to send a different key to heroku when using ssh. Follow any tutorial to create your ssh keys.
The key is getting SSH to use different keys for each Heroku account. How do you do configure this? You'll need to do 2 things:
1) You'll need to make a 'dummy' domain that your .ssh/config will intercept and reconfigure. This will tell ssh the 'actual' domain you want, and which special ssh key to use.
Host heroku.my_unique_key
HostName heroku.com
IdentityFile ~/.ssh/identity.heroku.my_unique_key
IdentitiesOnly yes
2) Change your .git/config to use that when using git push. Instead of heroku.com, use the dummy domain you set in your .ssh/config
[remote "heroku"]
url = [email protected]
[remote "heroku"]
url = [email protected]_unique_key:myapp.git
That's it :) A bit complicated and a bit simple at the same time. It has taken me 3 years of banging my head against the wall and trial and error to discover this info. It should be clearly documented somewhere, but at least it's a start.