How do you reapply commits on top of another base branch in Git?

How do you reapply commits on top of another base branch in Git?

a) git merge
b) git rebase
c) git pull
d) git cherry-pick

Answer:

b) git rebase

Explanation:

The git rebase command re-applies commits from the current branch on top of another base branch. It allows you to integrate changes from the base branch and rewrite commit history as if the branch was originally created from the updated base.

For example, git rebase main will rebase the current branch on top of the main branch, applying your changes after the latest main commits.

Rebasing creates a linear history, making it cleaner but should be used cautiously to avoid conflicts in shared branches.

Reference:

Top 100 Git and GitHub MCQ Questions and Answers

Scroll to Top