Generally, you will add a git remote for your Heroku app during the Heroku app creation process, i.e. heroku create
. However, if you are working on an existing app and want to add git remotes to enable manual deploys, the following commands may be useful.
Note that on Heroku, you must always use master
as the destination branch on the remote. If you want to deploy a different branch, you can use the syntax local_branch:destination_branch
seen below (in this example, we push the local staging
branch to the master
branch on heroku.
$ git remote add staging https://git.heroku.com/staging-app.git
$ git push staging staging:master
In some cases, your local branch may be missing some commits that were already deployed to Heroku, resulting in an error. If you are very sure you want to proceed, add the --force
(-f
) flag.
$ git push staging staging:master -f
By convention, the remote name "heroku" is typically used for the production application.
$ git remote add heroku https://git.heroku.com/app.git
$ git push heroku master
As @voke points out, you can alternatively use a Heroku CLI command to add your remote. However, it looks like this will always use the default remote name heroku
for the remote. If you would like to use a different name for your remote, see the "Rename a remote" section below.
$ heroku git:remote -a staging-app
Edit: Thanks to @nruth for pointing out you can supply a remote name to this command with the -r
flag.
$ heroku git:remote -a staging-app -r staging
As @Saworieza points out, all of the examples above use the https protocol for connecting to the remotes, but it is also possible to connect via ssh.
$ git remote add staging [email protected]:staging-app.git
$ git remote add heroku [email protected]:app.git
The -v
is the flag for "verbose" and includes the remote URL in addition to the remote name.
$ git remote -v
$ git remote rename heroku staging
If you have already created https remotes and want to switch them to use ssh, the following command can be used. This command can also be used to change the target URL without changing the protocol
$ git remote set-url staging [email protected]:staging-app.git
$ git remote set-url heroku https://git.heroku.com/production-app.git
I tried this way but the cmd give this push action was rejected
can u help me :(