126

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

How can I change the git master branch on git?

Promise Preston
  • 24,334
  • 12
  • 145
  • 143
Jon
  • 1,261
  • 2
  • 9
  • 3
  • Yes. I have created a new heroku app: heroku create myapp. But I have another app on heroku. I just want to change the git master to the new app. So that i can say git push heroku master. And the code will be oploaded to the new app not the old one. – Jon Jun 03 '11 at 12:27
  • possible duplicate of [Replace remote git repo (Heroku)](http://stackoverflow.com/questions/8265493/replace-remote-git-repo-heroku) – lambshaanxy Mar 05 '14 at 12:13

9 Answers9

197

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.

Mauro
  • 3,946
  • 2
  • 27
  • 41
  • 8
    Just followed this approach and appears to be the CURRENT correct way to do it. – Joe Sep 10 '14 at 23:16
  • 1
    As there was no correct answer designated by OP and this answer is by-in-large the answer to OP's question and has more upvotes than the "top" answer above does, why is this answer still shown below the lesser agreed upon answer? Thanks. – Devon Kiss Mar 24 '17 at 11:30
  • 5
    No need even to remove the old git remote. `heroku git:remote -a appname` - will replace the old one just fine. – Alexey Vol May 12 '17 at 07:43
108

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.

Abizern
  • 146,289
  • 39
  • 203
  • 257
24
  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.

U.A
  • 2,991
  • 3
  • 24
  • 36
11

This worked for me:

git remote set-url heroku <repo git>

This replacement old url heroku.

You can check with:

git remote -v
4

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

Source: https://devcenter.heroku.com/articles/git

Conor
  • 327
  • 6
  • 15
Akshata Dabade
  • 477
  • 5
  • 10
3

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

Community
  • 1
  • 1
Felipe Sabino
  • 17,825
  • 6
  • 78
  • 112
2

Remove Heroku remote URL from git repo
> git remote rm heroku
Set new Heroku URL from git repo
> git remote add heroku ##########

1

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.

Nash Worth
  • 2,524
  • 1
  • 21
  • 28
0

write in terminal if you already login with heroku from terminal..
heroku git:remote -a appname