0

I generally use the following steps:

  1. Create a feature branch.
  2. After the feature is developed, I merge master into feature branch to get it up to date with master.
  3. Push those merged changes to the feature branch.
  4. Finally, I merge the feature branch into master, to be picked up for release.

After step 4 if I see the commits in the 'master' branch one of them shows "Merge branch 'master' into ". This commit shows all the changes made by others while I was working on my feature. Which is fine but when I see this commit in master, it seems confusing and it shows huge commits. These were commits to the feature branch. Why are they appearing in the master branch?

Is there a way to merge feature branch to master but also ensure that only the feature changes show in the master commit log?

Vamsi
  • 365
  • 2
  • 8

1 Answers1

2

This is why you rebase. When you're ready to merge master into your branch to get the latest code from master, instead do git rebase master in your feature branch. This basically rolls back all your commits in your feature branch, gets the latest commits from master to "update" your feature branch, then replays your commits on top of those. This way when you finally merge your feature branch into master, you don't have a merge commit to begin with.

You can see a nice diagram explanation here.

yelsayed
  • 5,236
  • 3
  • 27
  • 38
  • Bonus points if you include a helpful diagram showing how rebasing avoids ugly (and confusing) merge commits. – Tim Biegeleisen Dec 01 '16 at 05:56
  • I don't think I'll do better than the link I added in the answer. :) – yelsayed Dec 01 '16 at 07:23
  • Thanks! rebase explains it. The Atlassian tutorial is super useful. – Vamsi Dec 02 '16 at 11:41
  • [This answer](http://stackoverflow.com/questions/34678950/git-branch-has-diverged-after-rebase-so-why-rebase) also helped as I faced the same issue after rebase. Basically, the lesson is to rebase until we've not pushed the branch to origin. After that, merge seems a better option. – Vamsi Dec 05 '16 at 05:26