Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merge remote changes into a branch that is not the current branch

Tags:

git

merge

I have multiple branches, and I would like to merge remote changes into a branch that is not my current branch.

For example:

git merge remote/branch some-other-branch 
like image 311
Ryan Kohn Avatar asked Dec 19 '12 15:12

Ryan Kohn


People also ask

Does merge change both branches?

No, merging does only affect one branch.

Does git merge merge into current branch?

Merging is Git's way of putting a forked history back together again. The git merge command lets you take the independent lines of development created by git branch and integrate them into a single branch. Note that all of the commands presented below merge into the current branch.


2 Answers

This is doable only if the local branch can be fast-forwarded to the remote head. While in any branch, to fetch the remote branch from origin and update the local head use:

git fetch origin remote_branch:local_branch 

Essentially, this is the reverse of how you open a new branch at origin with git push -u origin local_branch:remote_branch.

like image 192
V.S. Avatar answered Sep 30 '22 20:09

V.S.


There's an answer to a similar question that might do what you want.

From your repo root:

git push . remote/branch:some-other-branch 

This worked for me when I wanted to fast-forward master to a later commit just before I rebased to it from the branch I was in (not master).

like image 39
Steve Avatar answered Sep 30 '22 20:09

Steve