127

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

How can I change the git master branch on git?

Promise Preston
29.9k18 gold badges176 silver badges173 bronze badges
asked Jun 3, 2011 at 12:01
2
  • 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. Commented Jun 3, 2011 at 12:27
  • possible duplicate of Replace remote git repo (Heroku) Commented Mar 5, 2014 at 12:13

9 Answers 9

201

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.

answered May 21, 2014 at 23:11
Sign up to request clarification or add additional context in comments.

3 Comments

Just followed this approach and appears to be the CURRENT correct way to do it.
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.
No need even to remove the old git remote. heroku git:remote -a appname - will replace the old one just fine.
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.

answered Jun 3, 2011 at 12:31

4 Comments

How do I know what my origin is named?
can you explain what you meant here The -u will set this up as tracked. Thanks!
@uDay It means that when you ask for a pull, it will know to fetch and merge this branch
I would update this answer to remove the heroku remote initially - not the git remote origin master...
23
  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.

answered Jun 18, 2019 at 6:48

Comments

11

This worked for me:

git remote set-url heroku <repo git>

This replacement old url heroku.

You can check with:

git remote -v
answered Oct 8, 2018 at 4:09

Comments

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
4057 silver badges15 bronze badges
answered Mar 10, 2019 at 3:00

Comments

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

answered Jun 3, 2011 at 12:13

3 Comments

How do I change the git master?
What do you mean by that? by change the git master you mean changes files, then commit and push to it? rename it? What exactly are you trying to do?
Just saw your comment on the question, your are having problems with remote, and not with branches... check @Abizern's answer :)
2

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

answered Aug 20, 2022 at 11:34

Comments

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.

answered Jan 20, 2018 at 5:20

Comments

0

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

answered Sep 21, 2021 at 3:16

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.