1

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.

John Dui
  • 541
  • 3
  • 8
  • 15

1 Answers1

3

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)
             vvvv
 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)
       vvvvvvvvvv
 x--x--x--x--X--X        (master, origin/master)
    \            \
     f--f--f -----M      (foo)
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • and what if I want to merge one particular commit of the master branch into my branch `foo`? – John Dui Oct 28 '16 at 06:55
  • @JohnDui Then you can cherry-pick one or multiple commits from one branch to the other: http://stackoverflow.com/a/1994491/6309 – VonC Oct 28 '16 at 07:09
  • @JohnDui but beware of issues with cherry-picking mentioned in http://stackoverflow.com/a/13524494/6309 (see the two links mentioned in that answer) – VonC Oct 28 '16 at 07:10