Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use a different branch name when pushing to remote repo

Tags:

git

github

Say I added a new remote repo under my project folder by:

git remote add origin2 ADDRESS_OF_NEW_REMOTE_REPO

then, I start to push my code to my new remote repo. Locally, my branch name is "develop", I want to push to my new remote repo with a different branch name, say "production", can I simply do this by command:

git push origin2 production 

though locally, I am under branch "develop" ? What is the correct way to do this? and what potential problems could be caused by doing this?

like image 899
john123 Avatar asked Dec 01 '25 18:12

john123


1 Answers

$ git push yourremotename local_branch:remote_branch

(yourremotename here is remote name, often "origin", "github", "heroku" or similar)

So for you something like:

$ git push origin2 develop:production

For the most cases I think I would just rename the local branch to avoid confusion, if it's possible.

$ git branch -m develop production

This way it is easier to keep track as to what branch references which.

I understand though that for example Heroku would only deploy from master branch, so sometimes you do want to have the names separate.

like image 197
eis Avatar answered Dec 03 '25 11:12

eis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!