WalzoneInterview Prep
📞 Interviewing soon? Practice with a realistic AI mock phone interview — it calls you, then scores you. First 15 min FREE →

Git · Basic · question 12 of 100

What is a ’git rebase’, and when would you use it?

📕 Buy this interview preparation book: 100 Git questions & answers — PDF + EPUB for $5

In Git, git rebase is a command used to modify the history of a branch. The purpose of git rebase is to move the changes from one branch to another, effectively rewriting the history of the branch.

Here’s an example of how to use the git rebase command:

Suppose you have a branch called new-feature where you have made some changes to the codebase. You want to move those changes to the master branch. Here’s what you would do:

Switch to the branch that you want to move the changes into. In this case, you would switch to the master branch:

    git checkout master

Use the git rebase command to move the changes from the new-feature branch onto the master branch:

    git rebase new-feature

After running this command, Git will reapply the changes from the new-feature branch onto the master branch, effectively rewriting the history of the master branch.

One common use case for git rebase is to integrate changes from a feature branch into the main branch of the repository. By using git rebase instead of git merge, you can keep the commit history of the feature branch separate from the main branch, resulting in a cleaner and more readable history.

Here’s an example of how to use git rebase to integrate changes from a feature branch into the main branch:

    
    # Create a new feature branch called "new-feature"
    git checkout -b new-feature
    
    # Make some changes on the new feature branch
    ...
    
    # Switch back to the main branch
    git checkout master
    
    # Use git rebase to integrate the changes from the new feature branch into the main branch
    git rebase new-feature

In summary, git rebase is a powerful command that allows you to move changes from one branch to another, effectively rewriting the history of a branch. You can use git rebase to integrate changes from a feature branch into the main branch of a repository while keeping the commit history clean and readable.

Reading is step one. Saying it out loud is the interview. Our AI interviewer calls your phone and runs a realistic Git interview — then scores it.
📞 Practice Git — free 15 min
📕 Buy this interview preparation book: 100 Git questions & answers — PDF + EPUB for $5

All 100 Git questions · All topics