1

suppose I have a branch b1, done my development, pushed to the remote, and I want to merge into the remote master.I just wandering what's the difference between

git fetch
git checkout b1
git merge/rebase master
git push master

and

git fetch
git checkout master
git merge/rebase b1
git push master
user5324782
  • 177
  • 1
  • 1
  • 14
  • 2
    Possible duplicate of [What is the difference between merging master into branch and merging branch into master?](http://stackoverflow.com/questions/26384166/what-is-the-difference-between-merging-master-into-branch-and-merging-branch-int) – jub0bs Oct 22 '15 at 15:58
  • indeed, I am sorry. but there is a small difference :) I'v thrown the rebase into the mix. – user5324782 Oct 22 '15 at 16:00

2 Answers2

1

In first case the b1 will have all changes from master, but b1 could have something which is not in master.

The second case - opposite.

Just try to see different combinations in the log before/after merges: git log b1..master, git log master..b1.

kan
  • 28,279
  • 7
  • 71
  • 101
  • what is the recommend way? and when you mean could have something which is not in master, what exactly is it? could it be something committed right after the merge command issued? the change is too small, push when you push, git won't allow you to do it isn't – user5324782 Oct 22 '15 at 16:05
  • @user5324782 `master` is just yet another branch, same as `b1`. There is no difference at all, except of its name. "Something" - I meant commits made into a given branch before merge. You could also make commits after, they will be just more commits after merge... – kan Oct 22 '15 at 19:39
1

Before the merges, your repo looks something like

...-- * -- * -- * -- * master

...-- * -- * -- * -- * b1

After git merge/rebase master, only master consists of the merged history:

-- * -- * -- * -- * -- * master
                      /
...-- * -- * -- * -- * b1

After git merge/rebase b1, only b1 consists of the merged history:

...-- * -- * -- * -- * master
                      \
-- * -- * -- * -- * -- * b1

You probably want the first scenario, where you normally branch off master and would want the full history including all previous merges. However, if b1 is a long-lived branch, you may occasionally do the second merge as well, so that b1 keeps up-to-date with master.

chepner
  • 497,756
  • 71
  • 530
  • 681