0
0
Gitdevops~20 mins

Why rebasing creates linear history in Git - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Git Rebase Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
What does rebasing do to commit history?

Imagine you have a feature branch diverged from main. What does rebasing your feature branch onto main do to the commit history?

AIt creates a new linear sequence of commits by moving feature commits on top of main's latest commit.
BIt merges main into feature, creating a merge commit and preserving all branches.
CIt deletes the feature branch and replaces it with main branch commits.
DIt duplicates all commits from main into feature branch without changing order.
Attempts:
2 left
💡 Hint

Think about how rebasing changes the base of your feature branch commits.

💻 Command Output
intermediate
2:00remaining
Output after rebasing a feature branch

You have a main branch with commits A-B-C and a feature branch with commits D-E diverged from B. You run git rebase main on feature. What does git log --oneline --graph show for feature branch?

A* E<br>* D<br>* B<br>* C<br>* A
B* E' (rebased)<br>* D' (rebased)<br>* C<br>* B<br>* A
C* C<br>* B<br>* A<br>* D<br>* E
D* E<br>* D<br>* C<br>* B<br>* A
Attempts:
2 left
💡 Hint

Rebased commits get new commit IDs and appear on top of main's latest commit.

Troubleshoot
advanced
2:00remaining
Why does rebasing cause conflicts?

When rebasing a feature branch onto main, you encounter conflicts. Why does this happen?

ABecause rebasing resets the repository to an earlier commit, losing recent changes.
BBecause rebasing deletes all commits from main, causing missing files.
CBecause rebasing re-applies commits on top of main, conflicting changes in the same files cause conflicts.
DBecause rebasing merges main and feature branches automatically without checking differences.
Attempts:
2 left
💡 Hint

Think about what happens when commits are replayed on a different base.

🔀 Workflow
advanced
2:00remaining
Choosing between merge and rebase for a clean history

You want to keep your project history linear and easy to read. Which workflow should you use?

AUse <code>git rebase</code> to move feature branch commits on top of main before merging.
BUse <code>git merge --no-ff</code> to always create merge commits.
CUse <code>git cherry-pick</code> to copy commits from main to feature branch.
DUse <code>git reset --hard</code> to discard feature branch commits.
Attempts:
2 left
💡 Hint

Think about which command rewrites history to be linear.

Best Practice
expert
2:00remaining
When should you avoid rebasing a branch?

Which situation is a best practice reason to avoid rebasing a branch?

AWhen you want to update your branch with the latest commits from main.
BWhen you want to squash multiple commits into one for clarity.
CWhen you want to create a linear history before merging your feature branch.
DWhen the branch is shared with others and rebasing would rewrite public history.
Attempts:
2 left
💡 Hint

Consider the impact of rewriting history on collaboration.