Skip to content

Instantly share code, notes, and snippets.

@randallreedjr
Last active October 5, 2025 12:05
Show Gist options
  • Save randallreedjr/aa89e069371d07371882eea2df15fb4d to your computer and use it in GitHub Desktop.
Save randallreedjr/aa89e069371d07371882eea2df15fb4d to your computer and use it in GitHub Desktop.

Revisions

  1. randallreedjr revised this gist Jun 5, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion heroku-remote.md
    Original file line number Diff line number Diff line change
    @@ -44,7 +44,7 @@ $ git remote add heroku [email protected]:app.git

    ### List your git remotes

    The -v if the flag for "verbose" and includes the remote URL in addition to the remote name.
    The `-v` is the flag for "verbose" and includes the remote URL in addition to the remote name.

    ```
    $ git remote -v
  2. randallreedjr revised this gist Jun 5, 2020. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions heroku-remote.md
    Original file line number Diff line number Diff line change
    @@ -43,6 +43,9 @@ $ git remote add heroku [email protected]:app.git
    ## Other useful commands

    ### List your git remotes

    The -v if the flag for "verbose" and includes the remote URL in addition to the remote name.

    ```
    $ git remote -v
    ```
  3. randallreedjr revised this gist Jun 5, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion heroku-remote.md
    Original file line number Diff line number Diff line change
    @@ -15,7 +15,7 @@ In some cases, your local branch may be missing some commits that were already d
    $ git push staging staging:master -f
    ```

    ### Add a remote for your Production app and deployu
    ### Add a remote for your Production app and deploy
    By convention, the remote name "heroku" is typically used for the production application.
    ```
    $ git remote add heroku https://git.heroku.com/app.git
  4. randallreedjr revised this gist Jan 17, 2020. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions heroku-remote.md
    Original file line number Diff line number Diff line change
    @@ -28,6 +28,11 @@ As [@voke](https://gist.github.com/randallreedjr/aa89e069371d07371882eea2df15fb4
    $ heroku git:remote -a staging-app
    ```

    **Edit:** Thanks to [@nruth](https://gist.github.com/randallreedjr/aa89e069371d07371882eea2df15fb4d#gistcomment-3141611) for pointing out you can supply a remote name to this command with the `-r` flag.
    ```
    $ heroku git:remote -a staging-app -r staging
    ```

    ### Add a remote using the SSH protocol
    As [@Saworieza](https://gist.github.com/randallreedjr/aa89e069371d07371882eea2df15fb4d#gistcomment-2784952) 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.
    ```
  5. randallreedjr revised this gist Nov 22, 2019. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions heroku-remote.md
    Original file line number Diff line number Diff line change
    @@ -23,13 +23,13 @@ $ git push heroku master
    ```

    ### Add a remote via Heroku CLI
    As @voke points out, you can alternatively use a [Heroku CLI command](https://devcenter.heroku.com/articles/git#creating-a-heroku-remote) to add your remote. However, it looks like this will always use the default remote name `heroku`. If you would like to use a different name for your remote, see the "Rename a remote" section below.
    As [@voke](https://gist.github.com/randallreedjr/aa89e069371d07371882eea2df15fb4d#gistcomment-3079752) points out, you can alternatively use a [Heroku CLI command](https://devcenter.heroku.com/articles/git#creating-a-heroku-remote) 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
    ```

    ### Add a remote using the SSH protocol
    As @Saworieza points out, all of the examples above use the https protocol for connecting to the remotes, but it is also to connect via ssh.
    As [@Saworieza](https://gist.github.com/randallreedjr/aa89e069371d07371882eea2df15fb4d#gistcomment-2784952) 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
  6. randallreedjr revised this gist Nov 22, 2019. 1 changed file with 39 additions and 22 deletions.
    61 changes: 39 additions & 22 deletions heroku-remote.md
    Original file line number Diff line number Diff line change
    @@ -2,37 +2,54 @@

    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.

    # Add a remote for your staging app and deploy; 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 below (in this example, we push the
    # local `staging` branch to the `master` branch on heroku
    ## Adding a new remote

    ### Add a remote for your Staging app and deploy
    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 sure you want to proceed, add the --force (-f) flag
    ```
    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
    ### Add a remote for your Production app and deployu
    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
    ```

    # To see a list of your remotes
    $ git remote -v


    # As @voke points out, you can alternatively use a Heroku CLI command.
    # https://devcenter.heroku.com/articles/git#creating-a-heroku-remote
    # However, it looks like this will always use the default remote name "heroku"
    # You could then use git to rename the remote, as follows
    ### Add a remote via Heroku CLI
    As @voke points out, you can alternatively use a [Heroku CLI command](https://devcenter.heroku.com/articles/git#creating-a-heroku-remote) to add your remote. However, it looks like this will always use the default remote name `heroku`. 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
    $ git remote rename heroku staging
    ```


    # As @Saworieza points out, all of the examples above use the https protocol for connecting to the remotes,
    # but it is also to connect via ssh
    ### Add a remote using the SSH protocol
    As @Saworieza points out, all of the examples above use the https protocol for connecting to the remotes, but it is also to connect via ssh.
    ```
    $ git remote add staging [email protected]:staging-app.git
    $ git remote add heroku [email protected]:app.git
    ```

    ## Other useful commands

    # If you have already created https remotes and want to switch them to use ssh, the following command can be used
    $ git remote set-url staging [email protected]:staging-app.git
    ### List your git remotes
    ```
    $ git remote -v
    ```

    ### Rename a remote
    ```
    $ git remote rename heroku staging
    ```

    ### Change a remote URL or protocol
    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
    ```
  7. randallreedjr renamed this gist Nov 22, 2019. 1 changed file with 3 additions and 4 deletions.
    7 changes: 3 additions & 4 deletions heroku-remote.sh → heroku-remote.md
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,6 @@
    # 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
    # Working with git remotes on Heroku

    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.

    # Add a remote for your staging app and deploy; note that on Heroku, you must always use `master` as the
    # destination branch on the remote
  8. randallreedjr revised this gist Nov 22, 2019. 1 changed file with 20 additions and 6 deletions.
    26 changes: 20 additions & 6 deletions heroku-remote.sh
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,16 @@
    # 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
    # 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

    # Add a remote for your staging app and deploy; 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 below (in this example, we push the local `staging` branch to the `master` branch on heroku
    # Add a remote for your staging app and deploy; 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 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, resultin in an error. If you are sure you want to proceed, add the --force (-f) flag
    # In some cases, your local branch may be missing some commits that were already deployed to Heroku,
    # resulting in an error. If you are sure you want to proceed, add the --force (-f) flag
    $ git push staging staging:master -f


    @@ -22,4 +27,13 @@ $ git remote -v
    # However, it looks like this will always use the default remote name "heroku"
    # You could then use git to rename the remote, as follows
    $ heroku git:remote -a staging-app
    $ git remote rename heroku staging
    $ git remote rename heroku staging


    # As @Saworieza points out, all of the examples above use the https protocol for connecting to the remotes,
    # but it is also to connect via ssh
    $ git remote add staging [email protected]:staging-app.git
    $ git remote add heroku [email protected]:app.git

    # If you have already created https remotes and want to switch them to use ssh, the following command can be used
    $ git remote set-url staging [email protected]:staging-app.git
  9. randallreedjr revised this gist Nov 22, 2019. 1 changed file with 12 additions and 1 deletion.
    13 changes: 12 additions & 1 deletion heroku-remote.sh
    Original file line number Diff line number Diff line change
    @@ -11,4 +11,15 @@ $ 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
    $ git push heroku master

    # To see a list of your remotes
    $ git remote -v


    # As @voke points out, you can alternatively use a Heroku CLI command.
    # https://devcenter.heroku.com/articles/git#creating-a-heroku-remote
    # However, it looks like this will always use the default remote name "heroku"
    # You could then use git to rename the remote, as follows
    $ heroku git:remote -a staging-app
    $ git remote rename heroku staging
  10. randallreedjr revised this gist Nov 22, 2019. 1 changed file with 13 additions and 1 deletion.
    14 changes: 13 additions & 1 deletion heroku-remote.sh
    Original file line number Diff line number Diff line change
    @@ -1,2 +1,14 @@
    # 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

    # Add a remote for your staging app and deploy; 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 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 remote add heroku https://git.heroku.com/app.git
    $ git push staging staging:master
    # In some cases, your local branch may be missing some commits that were already deployed to Heroku, resultin in an error. If you are 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
  11. randallreedjr created this gist Dec 30, 2016.
    2 changes: 2 additions & 0 deletions heroku-remote.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    $ git remote add staging https://git.heroku.com/staging-app.git
    $ git remote add heroku https://git.heroku.com/app.git