gitmerge

merge one local branch into another local branch


I have multiple branches which are branched off the master (each in a separate subdirectory).

Before testing of the hotfix is finished I would like to have the code already available in newdevBranch, so I can continue developing with the fix in place.
(But since my experience with git is not that much I first started to play around with merge in a messAroundBranch, especially created to mess around in, before I mess up either newdevBranch or hotFixBranch)

In my messAroundBranch I first tried the following:

git merge feature/newdevBranch

but this gave the following error:

fatal: 'feature/newdevBranch' does not point to a commit

I next did a commit -a in my newdevBranch and tried again, but it keeps giving the same error.

What am I doing wrong? What should I do to merge the code from - in this case - newdevBranch with messAroundBranch?


Solution

  • First, checkout to your messAroundBranch:

    git checkout messAroundBranch
    

    Then merge the newdevBranch into messAroundBranch:

    git merge newdevBranch
    

    And if you want the updated commits of newdevBranch on hotFixBranch, you are probably looking for git rebase

    git checkout hotFixBranch
    git rebase newdevBranch
    

    This will update your hotFixBranch with the latest updates of newDevBranch.