What is git rebase?

Rebasing is the process of moving or combining a sequence of commits to a new base commit. Rebasing is most useful and easily visualized in the context of a feature branching workflow.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/f5eb66a6-62a5-4abb-a4b0-f2bb39e5ece6/Untitled.png

From a content perspective, rebasing is changing the base of your branch from one commit to another making it appear as if you'd created your branch from a different commit. Internally, Git accomplishes this by creating new commits and applying them to the specified base. It's very important to understand that even though the branch looks the same, it's composed of entirely new commits.

Usage

The primary reason for rebasing is to maintain a linear project history. For example, consider a situation where the master branch has progressed since you started working on a feature branch. You want to get the latest updates to the master branch in your feature branch, but you want to keep your branch's history clean so it appears as if you've been working off the latest master branch. This gives the later benefit of a clean merge of your feature branch back into the master branch.

You have to options for integrating your feature into the master branch: merging directly or rebasing and then merging. The former option results in a 3-way merge and a merge commit, while the latter results in a fast-forward merge and a perfectly linear history.

Git Rebase Standard vs Git Rebase Interactive

Git rebase interactive is when git rebase accepts an -i argument. This stands for "Interactive". Without any arguments, the command runs in standard mode.

Git rebase in standard mode will automatically take the commits in your current working branch and apply them to the head of the passed branch.

git rebase <base>