In Git, what is the main reason you should avoid rebasing branches that are already public (shared with others)?
Think about what happens when history changes after others have copied it.
Rebasing changes commit history. If others have copies of the original commits, their history will not match, causing confusion and conflicts when they try to update.
What will happen if you run git rebase main on a branch that has already been pushed and shared with others?
git checkout feature # feature branch is public and shared git rebase main
Consider what rebasing does to commit history and what is needed to update the remote branch.
Rebasing rewrites commits, changing their hashes. To update the remote branch, a force push is needed, which can disrupt others using that branch.
You want to update your public feature branch with the latest changes from main without rewriting history. Which workflow should you follow?
Think about how to keep history intact while incorporating new changes.
Merging adds a new commit combining histories without changing existing commits, so it is safe for public branches.
After rebasing a public branch and force pushing, your teammate reports conflicts when pulling. What is the best way to resolve this?
Consider how to align local history with the rewritten remote history.
Resetting the local branch to the remote branch discards conflicting local commits and matches the rewritten history, resolving conflicts.
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?
Think about when it is safe to rewrite history and when it is not.
Rebasing is safe on local/private branches before sharing. For public branches, merging preserves history and avoids disrupting collaborators.