Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merge two different remote branches in command line

I have 2 diffrent remotes

  1. origin1: "https://github.com/xxx.."
  2. origin2: "https://github.com/yyy.."

Each origin have a branch with same name. (branch_xxx)

How can i merge "origin1/branch_xxx" changes to "origin2/branch_xxx" using command line

like image 999
Asfath Shifan Avatar asked Oct 14 '25 04:10

Asfath Shifan


1 Answers

You can't work directly on origin2/branch_xxx which is not a local branch but a mere image of the last position of branch_xxx last time you fetched from origin2 (what's called a remote-tracking branch).

What you can do is work on a local copy (3 steps) :

1) Create a local copy of origin2/branch_xxx which will receive the merge

git checkout -b branch_xxx origin2/branch_xxx

2) Then merge origin1/branch_xxx into it (for the source branch no need for a copy)

git merge origin1/branch_xxx

(and deal with potential conflicts as usual)

3) Finally, push the result to origin2

git push origin2 branch_xxx

Note : to have a better understanding of what are these remote-tracking refs and how to work with them, take a look at this excellent summation in the official doc.

like image 137
Romain Valeri Avatar answered Oct 18 '25 03:10

Romain Valeri



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!