Search code examples
gitgit-clonegit-pull

Can I merge an updated branch into multiple feature branches without checking each of them out?


Here is a scenario.

There is the original main develop Branch on the server along with a Version Branch. Both the develop branch has a fix (1_otherFix Branch) and the version Branch has (2_otherFix Branch). Both fixes have been merged.

Server

develop Branch (Original)
---------------------------------------------------------------
     \                             \ 1_otherFix Branch /
      \                             \-----------------/
       \ versionX Branch
        \------------------------------------------------------
                        \ 2_otherFix Branch /
                         \-----------------/          

My Environment

I created a clone of that main develop branch (myDevelop) which a version branch (myVersionX) is generated via a checkout. (git checkout versionX).

I then created a new branch (myFix) off of the myVersionX branch.

myDevelop Branch (clone)
---------------------------------------------------------------
      \                             
       \ myVersionX Branch
        \------------------------------------------------------
               \
                \ myFix Branch
                 \---------------------------------------------

The objective is to update the clone, my main develop branch (myDevelop), and my version branch (myVersionX) as well as my fix branch (myFix) so that they all include the 2 merged fixes from the server (1_otherFix Branch) and (2_otherFix Branch).

How do I get all 3 branches in my environment updated using "git pull"?

Can I do a "git pull" from (myFix) branch to have it update all 3?

myDevelop Branch (clone)
---------------------------------------------------------------
      \                             
       \ myVersionX Branch
        \------------------------------------------------------
               \
                \ myFix Branch
                 \---------------------git pull------------------

Do I have to navigate to each branch and do a "git pull" ?

myDevelop Branch (clone)
------------------------------1 - git pull---------------------
      \                             
       \ myVersionX Branch
        \------------------------2 - git pull-------------------
               \
                \ myFix Branch
                 \-------------------3 - git pull-----------------

Do I have to navigate to each branch and do a "git pull" with the specific name ?

myDevelop Branch (clone)
------------------------------1 - git pull develop------------------
      \                             
       \ myVersionX Branch
        \------------------------2 - git versionX-------------------
               \
                \ myFix Branch
                 \-------------------3 - git pull-----------------

Can I do all 3 pulls from myFix branch?

myDevelop Branch (clone)
---------------------------------------------------------------
      \                             
       \ myVersionX Branch
        \------------------------------------------------------
               \
                \ myFix Branch
                 \---------------------git pull develop-------------
                                       git pull versionX
                                       git pull

Is there a simpler way to get all 3 updated?


Solution

  • Yes, you need to checkout each branch and to merge the original develop branch.

    Fetch the remote that is "hosting" the original develop branch first to ensure that your local GIT repository is aware of changes on this remote, and then, git checkout each of your 3 branches and perform a git merge myRemote/develop.

    As a side note, I never recommend to use git pull as it doesn't really help in understanding GIT under the hood (even though it's just a git fetch + git merge).