[git] How to change a Git remote on Heroku

I do not want to upload my app to the wrong domain.

How can I change the git master branch on git?

This question is related to git heroku

The answer is


  1. View Remote URLs

    > git remote -v

    heroku  https://git.heroku.com/###########.git (fetch) < your Heroku Remote URL
    heroku  https://git.heroku.com/############.git (push)
    origin  https://github.com/#######/#####.git (fetch) < if you use GitHub then this is your GitHub remote URL
    origin  https://github.com/#######/#####.git (push)
  1. Remove Heroku remote URL

    > git remote rm heroku

  2. Set new Heroku URL

    > heroku git:remote -a ############

And you are done.


If you're working on the heroku remote (default):

heroku git:remote -a [app name]

If you want to specify a different remote, use the -r argument:

heroku git:remote -a [app name] -r [remote] 

EDIT: thanks to ??????? ???????? For pointing it out that there's no need to delete the old remote.


This worked for me:

git remote set-url heroku <repo git>

This replacement old url heroku.

You can check with:

git remote -v

Assuming your current remote is named origin then:

Delete the current remote reference with

git remote rm origin

Add the new remote

git remote add origin <URL to new heroku app>

push to new domain

git push -u origin master

The -u will set this up as tracked.


here is a better answer found through Git docs.

This shows what the heroku remote is:

$ git remote get-url heroku

Found it here: https://git-scm.com/docs/git-remote Also in that document is a set-url, if you need to change it.


You can have as many branches you want, just as a regular git repository, but according to heroku docs, any branch other than master will be ignored.

http://devcenter.heroku.com/articles/git

Branches pushed to Heroku other than master will be ignored. If you’re working out of another branch locally, you can either merge to master before pushing, or specify that you want to push your local branch to a remote master.

This means that you can push anything you want, but you app at heroku will always point to the master branch.

But, if you question regards how to create branches and to work with git you should check this other question


If you have multiple applications on heroku and want to add changes to a particular application, run the following command : heroku git:remote -a appname and then run the following. 1) git add . 2)git commit -m "changes" 3)git push heroku master


Examples related to git

Does the target directory for a git clone have to match the repo name? Git fatal: protocol 'https' is not supported Git is not working after macOS Update (xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools) git clone: Authentication failed for <URL> destination path already exists and is not an empty directory SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443 GitLab remote: HTTP Basic: Access denied and fatal Authentication How can I switch to another branch in git? VS 2017 Git Local Commit DB.lock error on every commit How to remove an unpushed outgoing commit in Visual Studio?

Examples related to heroku

How to fix error "ERROR: Command errored out with exit status 1: python." when trying to install django-heroku using pip Can't push to the heroku ImproperlyConfigured: You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings How to enable CORS in flask Error: Cannot pull with rebase: You have unstaged changes How to solve error "Missing `secret_key_base` for 'production' environment" (Rails 4.1) Failed to execute 'postMessage' on 'DOMWindow': The target origin provided does not match the recipient window's origin ('null') 'heroku' does not appear to be a git repository Heroku 'Permission denied (publickey) fatal: Could not read from remote repository' woes How do I set up DNS for an apex domain (no www) pointing to a Heroku app?