The first thing to understand about the git merge and git rebase is that both solves the same problem ie combine the changes, they just do it in very different ways.
Consider what happens when you start working on a new feature in a dedicated branch, then another team member updates the master branch with new commits. This result in a commited history.
If you want the new changes into your feature branch, Now you have two option merging or rebasing.
The Merge option
Git merge takes the contents of a source branch and combines them with a target branch. This creates a new commit on the target branch that points to both the source and target branches.
The easiest option is to merge the master branch into the feature branch.
git merge feature master
This create a new "merge commit" in the feature branch that ties together the histories of the branches.
better for merge conflicts
easy to undo
Git rebase takes the commits from a source branch and replays them onto the target branch. This creates a new commit on the target branch for each commit on the source branch.
more readable graph
tougher to resolve conflict
Which to use
Git merge and rebase are two powerful tools that can be used to combine the changes from two branches. The best tool to use depends on the specific needs of your project.
When to use git merge
Git merge is a good option when you want to preserve the history of the source branch. It is also a good option when you want to combine changes from multiple branches.
When to use git rebase
Git rebase is a good option when you want to move changes from one branch to another. It is also a good option when you want to create a linear history for your project.