GIT Rebase vs Merge
How does Git Work?
For understanding the working of git, we need to understand the two fundamental concepts in git which is git commit and git branch. Let’s understand these two terms respectively.
What is a Commit?
Commit is defined as the location where the code and its changes are stored.
In git merge, looking at the end diagram, one can make out Commit A and B came from the feature branch. However, in the git-rebase diagram, it is difficult to understand where commits A and B came from. Therefore, we do git merge when we want our team to understand logs in a way where they can identify where each commit is coming from. We use Git Rebase when the logs of the repository will not be referred by anyone else. To summarise, we can use Git Rebase, when we are working on branches, which cannot be seen by other developers. And we use Git Merge when the target and source branch can be viewed by other developers.
How can Git Rebase and Git Merge be used together?
Let us take an example if we have a project which consists of a master branch with 3 commits as 1,2,3, and 2 feature branches with commits A, B on feature branch 1 and commits C, D on feature branch 2 which is depicted in Fig 14.
Let us assume that Developer A is working on feature branch 1.
To experiment with the code, he creates another branch Feature branch 2, does some changes in it, and finalizes it with Commits C and D.
He does not want anyone to know about his private branch, because it’s unnecessary. So, he can rebase Feature 2 on Feature 1.
Comments
Post a Comment