3

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?

eis
  • 51,991
  • 13
  • 150
  • 199
john123
  • 589
  • 3
  • 6
  • 16
  • Does this answer your question? [How can I push a local Git branch to a remote with a different name easily?](https://stackoverflow.com/questions/5738797/how-can-i-push-a-local-git-branch-to-a-remote-with-a-different-name-easily) – Tom Hale Jun 30 '23 at 14:12

1 Answers1

3
$ 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.

eis
  • 51,991
  • 13
  • 150
  • 199