History Is Messy, So Force-Push a Clean main?
A bad merge left main tangled with merge and revert commits. A teammate wants to rebase locally and force-push a clean history. Defend what you actually do.
Answer key reviewed by Branko Petric
Your decision
A bad merge left three ugly merge commits and a reverted-then-unreverted change on main. A teammate wants to rebase main locally to clean it up and git push --force to overwrite the shared history. What do you do, and why?
The situation
Someone merged a feature branch into main twice, and main now has a confusing tangle: three merge commits and a change that was reverted and then unreverted. The history reads badly, and a teammate has already produced a locally rebased, linear version that drops all the noise.
Context
The repo has four active contributors, all with their own local clones and a few in-flight feature branches based on the current main. The teammate wants to git push --force their rebased history so everyone gets a tidy main, and is pushing back in chat that it is a quick, low-risk cleanup.
Worked interview answers
- Scenario Based DevOps Interview Questions, With Worked Answers
Scenario based DevOps interview questions for Linux, Docker, CI/CD, Git and AWS, with first commands, the interviewer's pushback, and weak vs strong answers.
Related challenges
- You Pushed AWS Keys to a Public Repo
Live cloud keys just landed in a public GitHub repo. A teammate says delete the file and force-push. Defend what you do first.
- Deploys Are SSH + git pull at 5pm Friday. Why Change It?
The team ships by SSHing into prod and running git pull, often at 5pm Friday. A teammate says it has always worked. Defend what a real deploy needs without cargo-culting.
- Commit terraform.tfstate to the Repo So Everyone Shares It?
A teammate wants to commit terraform.tfstate to git so the whole team shares one state file. Defend the correct way to share Terraform state.
- A GitHub Action You Use Was Hijacked. Bump the Tag and Move On?
A third-party scanner action your repos pin by tag was hijacked for half a day. A teammate bumped the tag and wants to close the ticket. Defend what you do.