0

I had been working on a feature branch for some time now and when I try to merge to master, I notice the master has changes significantly, with some files in my branch have been moved to different folders on master and I have new files in my feature branch too.

I understand that I have two options, either to merge or rebase, but appreciate any input as to what would be the easiest option.

The branch I am working on is exclusive to me, so no problem re-writing history but master is obviously used by others and I am worried polluting it with history of changes from my feature branch

appreciate the step by step guide of this process as I am new to GIT and do not want to mess up things for others.

thanks

Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268

2 Answers2

1

Your best bet when your are working on a branch that is exclusive to you is to rebase. This will also allow you to deal with conflicts one change at a time and result in a cleaner history. The only reason you might not want to do that is if you have a company/team policy of doing no-ff merges on master. The process is this:

git checkout <feature>
git rebase master
...
    *potentially resolve conflicts*
    git add .
    git rebase --continue
    *repeat*
...
git checkout master
git merge <feature>

Advantages:

  • Cleaner history (no merge commits)
  • Deal with conflicts one commit at a time

Disadvantages:

  • Cannot rebase a branch that others are working on
  • On large projects having only merge commits on master can actually be cleaner. ie: merge feature 1, merge hotfix 2, merge feature 3.

However, in this case of Disadvantage 2 you could still rebase your changes and do a merge with --no-ff, that way you still get Advantage 2.

Massey101
  • 346
  • 1
  • 9
0

FWIW, my vote would be to merge instead of rebase. It makes it clear which commits contributed to your feature. Also, if you screw it up, you only have to revert one commit (the merge commit) to undo it. Plus, you are bound to have conflicts, and having a single merge commit to examine makes it easy to see if the conflicts are resolved correctly.

David Deutsch
  • 17,443
  • 4
  • 47
  • 54