Version Control
Git flow, rebase, cherry-pick, and pre-commit.
6 questions
MiddleTheoryVery commonHow do git merge and git rebase differ?
How do git merge and git rebase differ?
merge preserves both histories and records a merge commit, keeping the true but tangled timeline. rebase rewrites your commits onto the target tip for a clean linear history but changes hashes — avoid it on shared branches.
Common mistakes
- ✗Swapping the two — thinking
mergerewrites history andrebasepreserves it - ✗Believing rebase produces a merge commit like
mergedoes - ✗Assuming it is safe to rebase a shared or already-pushed branch
Follow-up questions
- →What is a fast-forward merge, and when does Git use one instead of a merge commit?
- →How does
git pull --rebasechange the default pull behavior?
JuniorTheoryCommonWhat does git cherry-pick do?
What does git cherry-pick do?
It applies the changes from one or a few specific commits, selected by hash, onto the current branch — copying individual commits across branches. Unlike merge or rebase, the picked commit gets a new hash.
Common mistakes
- ✗Expecting the picked commit to keep its original hash on the new branch
- ✗Thinking cherry-pick removes the commit from the source branch
- ✗Confusing cherry-pick of one commit with merging the whole branch
Follow-up questions
- →How can cherry-picking the same change later cause merge conflicts or duplicates?
- →What does
git cherry-pick -xadd to the commit message?
JuniorTheoryCommonWhat is the Git Flow branching model?
What is the Git Flow branching model?
A workflow with two long-lived branches: master (release history) and develop (integration), plus short-lived feature (off develop), release (off develop, to both), and hotfix (off master).
Common mistakes
- ✗Merging a
featurebranch straight intomasterinstead of intodevelop - ✗Branching a
hotfixoffdeveloprather than offmaster - ✗Forgetting that a
releasebranch must be merged back into bothmasteranddevelop
Follow-up questions
- →Why is a separate
releasebranch useful instead of taggingdevelopdirectly? - →How does trunk-based development differ from Git Flow?
MiddleTheoryCommonWhat does git rebase do, and what is interactive rebase for?
What does git rebase do, and what is interactive rebase for?
Rebase replays your commits onto another branch's tip, producing a linear history with new hashes. Interactive rebase (git rebase -i) is for cleaning up a branch before sharing: reorder, edit, squash, fixup, or drop commits via the todo list.
Common mistakes
- ✗Thinking interactive rebase rewrites working-tree files rather than rewriting the commits themselves
- ✗Believing
squashandfixupbehave identically and both throw away the commit message - ✗Assuming
git rebase -icannot reorder ordropcommits, only reword them
Follow-up questions
- →When would you choose
squashoverfixupduring an interactive rebase? - →What does
git rebase --ontolet you do that a plain rebase cannot?
JuniorTheoryOccasionalWhat is a pre-commit hook used for?
What is a pre-commit hook used for?
It is a client-side Git hook script that runs automatically before a commit is recorded. It can lint, format, run quick tests, or check style like PEP8, and abort the commit if checks fail. Hooks live in the hooks dir.
Common mistakes
- ✗Thinking
pre-commitruns on the server after push rather than locally - ✗Believing the hook cannot block or abort a failing commit
- ✗Assuming hooks are a GitHub feature rather than core Git
Follow-up questions
- →Why are Git hooks not version-controlled by default, and how do teams share them?
- →How does the
pre-commitframework differ from a raw Git hook script?
SeniorTheoryOccasionalWhy does rebasing require a force push, and what is --force-with-lease?
Why does rebasing require a force push, and what is --force-with-lease?
Rebase rewrites commits with new hashes, so the remote diverges and a normal push is rejected. --force overwrites it but can clobber teammates' commits pushed since you fetched. --force-with-lease overwrites only if the remote still matches.
Common mistakes
- ✗Thinking a normal
pushsucceeds after a rebase without any force flag - ✗Treating
--forceand--force-with-leaseas fully interchangeable - ✗Believing a plain force push can never overwrite a teammate's commits
Follow-up questions
- →What remote state does
--force-with-leasecheck, and when does that check fail? - →How does
git refloghelp you recover commits lost by a bad force push?