John Dui John Dui - 9 months ago 66
Git Question

How to merge one branch change to another?

I have two branches on my local, i.e. master and foo. I recently took a pull from origin and updated my master branch. Now I want to merge those changes into the branch foo and then commit and push those changes in that branch itself?

How to do I do that?

I can't seem to wrap my head around the merge command.

Answer Source

It should be as simple as:

git checkout foo
git merge master

But that will merge all commits since foo started from master (or at least since master was last merged into foo: see git merge-base)

              (new commits after git pull)
 x--x--x--x--X--X  (master, origin/master)
     f--f--f       (foo)

Merges into

         (ALL those commits are merged in foo: x as well as X)
 x--x--x--x--X--X        (master, origin/master)
    \            \
     f--f--f -----M      (foo)