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

Git · Advanced · question 44 of 100

Can you explain the concept of a "rebase conflict" and how to resolve it?

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

A "rebase conflict" occurs when you attempt to rebase a branch onto another branch, and Git encounters a change in the original branch that conflicts with a change in the branch being rebased. This can happen when two different changes modify the same file or the same lines of code within a file.

When a rebase conflict occurs, Git will pause the rebase process and inform you of the conflict. You will then need to resolve the conflict manually before the rebase process can continue.

Here’s an example of how to resolve a rebase conflict:

Start the rebase process:

    git checkout feature-branch
    git rebase master

Git will pause the rebase process and inform you of the conflict. You can use the git status command to see which files have conflicts:

    Unmerged paths:
    (use "git add <file>..." to mark resolution)
    
    both modified:   file.txt

Open the conflicted file(s) in your text editor and look for the conflict markers. These markers will indicate where the conflicting changes occurred:

    <<<<<<< HEAD
    This is the version of the file from the feature-branch.
    =======
    This is the version of the file from the master branch.
    >>>>>>> master

Edit the file to resolve the conflict. You can either choose one version of the change or create a new version that combines both changes. Once you have resolved the conflict, save the file.

Use the git add command to stage the resolved file:

    git add file.txt

Continue the rebase process:

    git rebase --continue

If there are additional conflicts, repeat steps 3-6 until all conflicts have been resolved and the rebase process has completed.

It’s important to note that a rebase conflict can be more complex than the example above, especially if multiple files or lines of code are in conflict. In some cases, you may need to manually edit the files to resolve the conflicts.

In summary, a rebase conflict occurs when Git encounters conflicting changes in the branch being rebased. To resolve a rebase conflict, you will need to manually edit the conflicted file(s) and choose which version of the change to keep. Once you have resolved the conflict, you can continue the rebase process.

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