DevOps(Day-13): Git Rebase vs. Merge: A Complete Guide

 

Git rebase is a command that lets users integrate changes from one branch to another, and the logs are modified once the action is complete. Git rebase was developed to overcome merging’s shortcomings, specifically regarding logs.

Git merge is a command that allows developers to merge Git branches while the logs of commits on branches remain intact.

The merge wording can be confusing because we have two methods of merging branches, and one of those ways is actually called “merge,” even though both procedures do essentially the same thing.

In summary, here’s an image that shows an initial branch, a Git rebase, and a Git merge.

Git rebase takes all the changes, and compresses them into a single patch and integrates this new patch onto the target branch. Then, it moves the completed work from one branch to another, typically the master branch. In the process, rebase flattens the history, removing unwanted entries.

Git merge, on the other hand, only changes the target branch and creates a commit, preserving the history of the source branch.

Both the rebase and merge commands exist for the same reason: they combine the work of multiple developers into a single entity, integrating changes between branches. That about sums up their similarities. On the other hand, their differences are considerably more profound.

It’s possible to use both Git rebase and Git merge in the same project. For example, you can work on a feature branch, create another feature branch off it, make your changes, and finalize them as commits. You could then Git merge both feature branches, then use a Git rebase to merge the feature branches into the main branch. This way, you, as the developer, can do you work on a feature branch, but other team members won’t see it when they look at the main branch.

Put another way; you can use Git rebase to work on a private branch, then do Git merge to bring everything together into one coherent timeline.

Git reset,revert are powerful commands that undoes changes, moving the repository back to a previous commit, and eliminating any changes made after the commit. It’s literally undoing changes.

Comments

Popular posts from this blog

DevOps(Day-97): Meta-Arguments in Terraform

DevOps(Day-95): Auto Scaling with Terraform

DevOps (Day-1) Introduction