Moon4u Moon4u - 3 months ago 11
Git Question

Merging local-only branches with a remote branch

I'm kinda new to git and I don't understand something. Let me explain.

I have 2 branches that are tracked on remote. There is a common code between them and I want to isolate this code in a third local-only branch (ie not pushing the changes to the origin). After that I want to merge this local branch with the other 2 branches.

Now the question is - when I push from my 2 branches to the origin, is the master branch going to be aware of this third (local-only) branch that I made? And is this going to make the merging between the 2 branches easier?

Answer

So it sounds like you have two branches, something like:

       A-B-C   br1
      /
-*-*-M         master
      \
       U-V-W   br2

And you want to extract a new branch for some common changes - let's called that shared:

       A-B-C   br1
      /
-*-*-M-----S   shared
      \
       U-V-W   br2

And then merge that branch into your other existing branches?

       A-B-C-D br1
      /     /
-*-*-M-----S   shared
      \     \
       U-V-W-X br2

Assuming I have understood your description correctly:

when I push from my 2 branches to the origin, is the master branch going to be aware of this third (local-only) branch that I made?

No, master will stay at commit M until you do something to it (commit, merge, reset, etc).

And is this going to make the merging between the 2 branches easier?

Probably It really depends on the nature of commit S and its relationship to the other changes from which you extracted your shared changes, but generally it's a good idea to recognize such shared changes and finish them in isolation before merging them back into the branches that depend on the common code.

Comments