Fix Repository with Unrelated Histories
Zscaler ☯️ Medium Git
Beginner Mode

Start your terminal to use beginner mode.

Scenario:

The repository at /home/interview/repo is in a broken state. Local and remote branches have diverged with no common ancestor. Consequently, git push origin main fails with a non-fast-forward error, and git pull origin main fails because the histories are unrelated.

Task:

Navigate to /home/interview/repo. Merge and linearize the unrelated histories (using rebase) to create a single commit sequence.

Example:

# Before (Broken)
$ git pull origin main
fatal: refusing to merge unrelated histories

# After (Fixed - Linear History)
$ git pull origin main
Already up to date.

$ git log --oneline --decorate
e8f9g0h (HEAD -> main, origin/main) Add local feature B
d7e8f9g Add local feature A
b5c6d7e Add remote config
a4b5c6d Remote initial commit

Terminal requires a larger screen

Open this page on a desktop or tablet (≥ 768px) to launch the terminal and practice hands-on.

Linux Terminal Environment

Write and execute your solution in the terminal below.

Sign In

Track

Question Difficulty Company Access
Need more practice in this area? Explore more questions →