How do you rebase a branch in Git?

How do you rebase a branch in Git?

a) git merge branch
b) git rebase branch
c) git pull branch
d) git sync branch

Answer:

b) git rebase branch

Explanation:

The git rebase branch command is used to apply the commits from one branch on top of another. It rewrites the commit history to make it appear as though the branch was created from the latest commit in the base branch.

For example, git rebase main will reapply your branch’s commits on top of the latest commits in the main branch.

Rebasing is useful for keeping a clean and linear project history, but it should be used carefully, especially on shared branches.

Reference:

Top 100 Git and GitHub MCQ Questions and Answers

Scroll to Top