0
0
Gitdevops~20 mins

Golden rule of rebasing (never rebase public) in Git - Practice Problems & Coding Challenges

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
Why should you never rebase public branches?

In Git, what is the main reason you should avoid rebasing branches that are already public (shared with others)?

ARebasing public branches rewrites history, causing conflicts for others who have based work on the original commits.
BRebasing public branches deletes all previous commits permanently from the repository.
CRebasing public branches automatically merges all changes without conflicts.
DRebasing public branches speeds up the repository but loses commit messages.
Attempts:
2 left
💡 Hint

Think about what happens when history changes after others have copied it.

💻 Command Output
intermediate
2:00remaining
Output of rebasing a public branch

What will happen if you run git rebase main on a branch that has already been pushed and shared with others?

Git
git checkout feature
# feature branch is public and shared
git rebase main
AGit refuses to rebase and shows an error about public branches.
BGit merges main into feature branch without changing commit hashes.
CGit rewrites the feature branch commits on top of main, changing commit hashes and requiring force push.
DGit deletes the feature branch automatically.
Attempts:
2 left
💡 Hint

Consider what rebasing does to commit history and what is needed to update the remote branch.

🔀 Workflow
advanced
2:30remaining
Safe workflow to update a public branch without rebasing

You want to update your public feature branch with the latest changes from main without rewriting history. Which workflow should you follow?

ADelete the feature branch and create a new one from main.
BUse <code>git merge main</code> on your feature branch to combine changes without rewriting history.
CUse <code>git rebase main</code> and then force push to update the public branch.
DReset the feature branch to main using <code>git reset --hard main</code>.
Attempts:
2 left
💡 Hint

Think about how to keep history intact while incorporating new changes.

Troubleshoot
advanced
2:30remaining
Resolving conflicts after rebasing a public branch

After rebasing a public branch and force pushing, your teammate reports conflicts when pulling. What is the best way to resolve this?

AYour teammate should ignore the conflicts and continue working.
BYour teammate should delete their local branch and clone the entire repository again.
CYour teammate should run <code>git pull --rebase</code> repeatedly until conflicts disappear.
DYour teammate should reset their local branch to the remote branch using <code>git reset --hard origin/branch</code>.
Attempts:
2 left
💡 Hint

Consider how to align local history with the rewritten remote history.

Best Practice
expert
3:00remaining
Choosing the right strategy for updating shared branches

You manage a shared repository with many collaborators. Which strategy best follows the golden rule of rebasing to keep history clean and avoid disrupting others?

AUse rebasing only on local or private branches before pushing, and use merging for public branches.
BAlways rebase all branches, including public ones, to keep history linear.
CNever rebase any branch; always merge everything to avoid any history rewriting.
DRebase public branches but never merge to keep the repository clean.
Attempts:
2 left
💡 Hint

Think about when it is safe to rewrite history and when it is not.