Rocky Inde Rocky Inde - 3 months ago 16
Git Question

Is merging from updated remote or unpushed tracking branch the same?

Suppose, I have two feature branches

fb_a
and
fb_b
both checked out from
master
at the same point of time. Now, will the following sets of steps lead to the same final state with respect to
origin/fb_b
?

Steps 1:

1) git checkout fb_a
2) git commit -m "change" # commit some change
3) git push # push the changes
4) git checkout fb_b
5) git merge origin fb_a # merge from remote branch
6) git push


Steps 2:

1) git checkout fb_a
2) git commit -m "change" # commit the **same change**
3) git checkout fb_b # fetch the commit in fb_b
4) git merge fb_a # merge from tracking branch
5) git push


Kindly, provide any explanation towards the same.

Answer

Both merges can be different (depends on the circumstances). In the first scenario, you merge the commit from origin/fb_a, from that state git last time saw where it pointed to. In the second scenario you take your current local revision.

Say the following is you current local repo, and you have two commits on fb_b, which are not at the remote repo:

    fb_a
o---A
 \
  o---OB----------o----B
      origin/fb_b      fb_b

The first merge will result in

         fb_a
o---A----M
 \      /
  o---OB----------o----B
      origin/fb_b      fb_b

The second merge will lead to

                         fb_a
o---A--------------------M
 \                      /
  o---OB----------o----B
      origin/fb_b      fb_b