PART 1 : "How does git know where to push to?"
Before executing the above mentioned command:
$ git push heroku master
There are always few other steps to execute: Installing Git and Heroku, creating a local Git repo, signing-up to heroku, log-in heroku via command-line, creating heroku handle to hosting point (explained in PART 2)
1. A local Git repository:
$ git init
Initialized empty Git repository in .git/
$ git add .
$ git commit -m "my first commit"
Created initial commit 5df2d09: my first commit
44 files changed, 8393 insertions(+), 0 deletions(-)
create mode 100644 README
create mode 100644 Procfile
create mode 100644 app/controllers/source_file
...
2. Have sign-up(ed) for Heroku and logged-in via command-line:
$ heroku login
Enter your Heroku credentials.
Email: user@example.com
Password:
Could not find an existing public key.
Would you like to generate one? [Yn]
Generating new SSH public key.
Uploading ssh public key /Users/adam/.ssh/id_rsa.pub
So by running $ git push heroku master
you have pushed the code/app to Heroku.
PART 2: but what does heroku and master indicate?
It is more of a Git question than Heroku - Heroku is a hosting platform, which depends on Git (Distributed Version Control System) for deployment.
The basic concept of 'push' is pushing some thing (file, app, ..) we have locally (in our working machine) to somewhere else, in this case to a remote repository (remote machine).
In Git before using 'push' we create a remote (handle) which acts as a reference to a remote repository (Complete URL), we do so using the following command:
$ git remote add <remote-name-of-our-choice> <URL-where-you-be-pushing-yourapp>
The basic structure of 'push' command is:
$ git push <remote-name> <branch>
So $ git push heroku master
is actually pushing your code/app/file (from some local Git repo) to a remote repo 'heroku' .
wondering when this 'heroku' remote got created, it was added when you executed $ heroku create
$ heroku create
Creating stark-fog-398... done, stack is cedar
http://stark-fog-398.herokuapp.com/ | git@heroku.com:stark-fog-398.git
Git remote heroku added
Do notice the last line "Git remote heroku added".
to make it more clear, here's a Git command to check/output all the remotes:
$ git remote -v
will display something similar to the following
$ git remote -v
heroku git@heroku.com:somerepo.git (fetch)
heroku git@heroku.com:somerepo.git (push)
So we can assume that the following command was executed (implicitly) somewhere, when you did $ heroku create , hence creating the heroku remote to some heroku repo (url)*
$ git remote add heroku git@heroku.com:somerepo.git