Skip to content

Sauter Git Workflow : Merge a feature branch in another feature branch

Damien Buhl (alias daminetreg) edited this page Aug 4, 2014 · 4 revisions

It is possible that you are working on a feature branch and you need to merge the features of another feature branch to be able to develop further ( e.g. Your new gui needs the functionality of the new config file parser), to do this simply perform the following :

SourceTree

  • Checkout locally the feature branch you want to take as merge source ( e.g. feature/new-config-files-format)

    Checkout the branch you want to merge

  • Checkout the feature branch where you want to merge things in ( e.g. feature/ui-redesign)

    Checkout the branch you want to have as result of the merge

  • Right click on the feature branch you want to merge ( e.g. feature/new-config-files-format) and click on Merge feature branch into current branch

    Merge the other branch in the currently checked-out one

Command Line

  • Checkout locally the feature branch you want to take as merge source ( e.g. feature/new-config-files-format)

    git checkout -b feature/new-config-files-format origin/feature/new-config-files-format
    git pull origin
  • Checkout the feature branch where you want to merge things in ( e.g. feature/ui-redesign)

    git checkout feature/ui-redesign
  • Now merge the feature branch you want the changes in your current one :

    git merge feature/new-config-files-format

    If there are no unresolvable conflict git will ask you to create a commit to validate the merge, in case there are conflicts you'll need to open the merge resolution tool:

    Auto-merging tests/t01-rawobj.c
    CONFLICT (content): Merge conflict in tests/t01-rawobj.c
    Removing src/revwalk.h
    Auto-merging src/oid.c
    Automatic merge failed; fix conflicts and then commit the result.
    
    git mergetool
    Merging:
    tests/t01-rawobj.c
    
    Normal merge conflict for 'tests/t01-rawobj.c':
      {local}: modified file
      {remote}: modified file
    Hit return to start merge resolution tool (kdiff3):
    

    This will drive you through all the steps of the merge, and ask you which changes you want to keep and which not. When changes are two files modified at the same time it should open up kdiff3, which will present you a merge resolution window.

    kdiff3 resolving conflicts

    Finally the merge can be validated by a commit. If you prefer aborting the merge because you are unsure, there is a command : git merge --abort.