views:

70

answers:

4

I'm 15 and have just started using source control systems to manage my code a little better, so I'm a little new to this stuff. Right now I have this repository:

[a]---[b]---[d]---[f] master
        \
         \
          [c]---[e]   develop

I want to wind up here:

[a]---[b]---[d]---[f]---[g]  master
        \               /
         \             /
          [c]---[e]---/      develop

where g is equivalent to performing commits [c] and [e] on [f]. This is git checkout master; git merge develop, right?

+1  A: 

You want git checkout master; git merge develop.

This is because git merge takes the name of a branch that you want to merge into the currently checked out branch. Thus, you check out your desired destination branch (master) and then merge the other branch into it (develop).

If you take a look in the first "Description" section on the git-merge man page, you'll see a diagram almost identical to yours (albeit flipped vertically) that describes this.

Amber
A: 

It is git checkout master to get on 'master' branch, then git merge develop to merge 'develop' branch into current 'master' branch.

Jakub Narębski
+1  A: 

Another great help about merge is http://progit.org/book/ch3-2.html and http://gitref.org/branching/#merge.

juniorbl
+4  A: 

The picture you drew looks like the result of git merge, but your description of what you want to happen sounds like git rebase.

Borrowing from the "Rebasing" chapter of the git community-book, if you're on the mywork branch and say

$ git merge origin

you'll get

git merge history

Think of a merge as cramming together two different snapshots: in this case C4 and C6 came together to make C7.

Rebase creates a tree that looks just like C7, but its history looks completely different. Say instead of the merge, you gave the command

$ git rebase origin

you'd get

alt text

When you find yourself wishing, 'I really wish I'd created the mywork branch at C4 instead of C2,' git rebase is the djinni that will grant it.

You could also think of rebase as cutting a branch out of your history and transplanting it on a different point. Don't miss the subtle change from C5 and C6 to C5' and C6'. Although the trees will look the same, they'll have different parents, thus changing their git identities.

Greg Bacon
Let's say that no two commits touch the same file. You'd wind up with the same result whether you merged or rebased, right?
wxyz
@wxyz Yes, the resulting trees will be the same, but their histories will differ as diagrammed above. Using `git rebase` can help keep your history linear.
Greg Bacon