0

I have branch master containing those commits :

C1
C2
C3

then I created branch B1 from master containing those commits

B1
B2
B3

how can I put now B1 in the head of master and keeping all commits like this :

C1
C2
C3
B1
B2
B3
bouqbouq
  • 973
  • 2
  • 14
  • 34
  • Rebase is what you are looking for, not merge. Read: http://stackoverflow.com/questions/804115/when-do-you-use-git-rebase-instead-of-git-merge http://stackoverflow.com/questions/16666089/whats-the-difference-between-git-merge-and-git-rebase – Thibault D. Oct 26 '16 at 13:00
  • Do you mean how can you put B1B2B3 on top of C1C2C3 ? Because if you branched out from master after C1C2C3. Then your current branch would be on top of C1C2C3. –  Oct 26 '16 at 18:32

2 Answers2

0

I think this will do what you want...

# Make sure you have the lastest master
git fetch
git checkout master
git rebase origin/master

# Make sure B1 sits atop the lastest master
git checkout B1
git rebase master

# (Fast-forward) Merge back to master
git checkout master
git merge B1
Jamie Bisotti
  • 2,605
  • 19
  • 23
  • how about two overlapped branches? I have master and B1 and B2, each branch has lot of commits, I want to merge everything to master by keeping all commits of master and B1 and B2 – bouqbouq Oct 26 '16 at 13:37
  • I think it is poor practice to change the question (or ask a different one) in the comment of an answer. If this answer addressed our original question, accept it. If you have another question, add a separate question. The more details you provide the more likely you'll get a helpful answer. Thanks. – Jamie Bisotti Oct 26 '16 at 18:31
  • @MakhloufGharbi: branches in Git do not overlap. Branch *names* like `master` and `B1` simply point to a commit. Each commit points back to its immediate ancestor ("parent") commit and the chain of back-pointers forms the history of commits, which (confusingly) is *also* called "a branch". `git merge` makes a new commit that points back to *two* (or more) parent commits, hence joining up separate chains. See also http://stackoverflow.com/questions/25068543/what-exactly-do-we-mean-by-branch – torek Oct 26 '16 at 18:35
0
git checkout master
git merge B-branch

// solve conflicts if they are

Mikl
  • 109
  • 3