Git rebasing is a helpful tool that allows developers to integrate changes from one branch into another in a cleaner and more streamlined way than merging. One of the main advantages is that it can help keep the Git history more organized and easier to follow. By replaying the changes from the feature branch onto the main branch, Git can create a linear history that shows the progression of the code over time in a more straightforward manner.
For example, to rebase your current branch to “master,” you typically use the following command:
git rebase master
During the rebase process, Git considers two sets of commits: the “theirs” and “ours” commits. The “ours” commits are the changes made on the branch that the feature branch is being rebased onto, while the “theirs” commits are the changes made on the feature branch.
There are different strategies to apply:
git rebase -Xours master
git rebase -Xtheirs master
Using the “theirs” strategy during a rebase means that Git will keep the changes made in the current branch and discard any changes made in the branch we’re rebasing onto. In contrast, using the “ours” strategy means that Git will keep the changes made in the branch we’re rebasing onto and discard any changes made in the current branch.