

We have to specify all the three branches names in this case because we are holding the changes from feature1 branch while replaying them in the main branch from feature2 branch: C8 and C9), and then replay them on the main branch by using the –onto option of git rebase.

With git rebase, we can “replay” the changes in the feature2 branch (that are not in the feature1 branch, i.e. Now suppose that we have decided to merge the feature2 changes to the mainline for the release, but we also want to hold the feature1 changes until they are tested further. Finally, we go back to the feature1 branch and commit a few more changes: Now, we branch off the feature2 branch to make some additional changes. Let’s say we have branched a feature1 branch from the mainline, and added some functionality to our project, and then made a commit. Let’s understand the working of git rebase by looking at history with a topic branch off another topic branch. If we consider it in the context of a feature branching workflow, we can visualize it as follows: A rebase is the way of migrating or combining a sequence of commits to a new base commit. Let’s have a look at the concept of git rebase. This commit contains all the changes from the source branch. Once Git has found a common base commit, it will create a new “merge commit”, that will combine the changes of each queued merge commit sequence.Īfter a merge, we have a single new commit on the branch we merge into. In the scenario which we have taken, git merge takes two commit pointers and tries to find the common base commit between them. Let’s take an example in which we will mainly focus on branch merging patterns.

In the most common cases, we use git merge to combine two branches. We use git merge for combining multiple sequences of commits into one unified history. Git merge is often used in combination with git checkout for the selection of the current branch, and git branch -d for deleting the obsolete source branch. It’s important to note that while using git merge, the current branch will be updated to reflect the merge, but the target branch remains untouched. The git merge command lets us take independent branches of development and combine them into a single branch. A merge is a way to put a forked history back together.
GIT REBASE FAST FORWARD CODE
