Interview Q&A / Git & GitHub

BeginnerQuick answer1 min readUpdated 3 Oct 2026

What is the golden rule of rebasing?

SHORT ANSWER

Never rebase commits that other people have already pulled. Rebase creates new commits with new hashes, so teammates who have the old ones end up with duplicated or conflicting history.

Explain it simply

Imagine a group assignment that your friends already copied from your shared drive. If you silently rewrite your file and replace it, their copies no longer match yours, and combining the work becomes painful.

Rebase does not move commits, it recreates them with different parents and so different hashes. If those old commits live on a shared branch like main, everyone else still holds the originals. When they pull, Git sees both versions and produces duplicates or conflicts. Rebasing your own unpublished feature branch is fine. If you must rewrite a pushed personal branch, use git push --force-with-lease.

Example

bash
git switch feature/profile   # my own branch, not yet shared
git rebase main              # safe

git switch main
git rebase feature/other     # risky: main is shared by everyone

What to say in the interview

"The golden rule is to never rebase commits that exist outside my local repository and that others may have based work on. Rebase rewrites hashes, which causes duplicated commits for teammates. On my own private branch it is fine, and I push it with --force-with-lease."

#git#rebase#best-practice

Related questions

Practise more Git & GitHub questions

Test your recall with short answers, then return to the detailed explanations when you need context.

Open Git & GitHub quick answers →

Get new questions like this by email

One short email when something new and useful lands. No spam, unsubscribe in one tap.

By subscribing you agree to the Privacy Policy.