
"Should I rebase or merge master? What are the differences?" Not long ago, I remembered asking those questions during my first software internship. Let me share you some of my thoughts.
Main Goal
You are working in your dedicated feature-a branch. You want to update your branch with the latest master which is the main goal. Both git rebase and git merge can help you to achieve it. But they do it in different ways.
Git Rebase
git rebase shifts your entire feature branch and points to the latest master.
git checkout feature-a
git rebase masterUnder the hood, git rebase rewrites project history. It creates brand new commits from the original feature branch_(see the diagram below)_. Rebasing gives us cleaner project history. However, git rebase can be a bit chaotic if someone is also working on your feature branch. In this case, I prefer to use git merge option.
Git Merge
git merge creates merge commit in your feature branch. It is much simpler than git rebase.
git checkout feature-a
git merge masterConclusion
To conclude, the followings are what I normally use in my day-to-day-work:
- Use
git rebaseif I am the only one working on my feature branch. - Use
git mergeif other developer are also working on feature branch. - Only use either
git rebaseorgit merge, one at a time. In other word, - Do not use
git rebaseif your branch hasgit merge masterin the past (I messed this one up before.

