Two branches both regenerated `package-lock.json` and it conflicts every time. What's the clean approach?
IntermediateScenarioBranching and Merging Workflows
Answer
Situation read → Lockfiles are generated, so hand-merging them is error-prone.
What I'd do →
- Resolve
package.jsonfirst (that is human-owned). - Take either side of the lockfile, then regenerate it:
git checkout --theirs package-lock.json
npm install
git add package-lock.json package.json
- Optionally register a merge driver or CI check so the lockfile is verified with
npm ci.
Why → The lockfile must match the final package.json. Regenerating guarantees consistency, and npm ci in CI catches drift.
Interview tip → The same pattern applies to yarn.lock, poetry.lock, go.sum.
More on Branching and Merging Workflows
You run `git pull` and Git stops with a merge conflict in `app.py`. What do you do?BeginnerYour feature branch is three weeks old and `main` has moved a lot. Merge `main` in, or rebase onto it?IntermediateThe team argues about fast-forward merges versus merge commits on `main`. How do you settle it?BeginnerA teammate branched from the wrong base, and their PR shows 40 unrelated commits. How do you fix it?IntermediateBefore merging, you want to see exactly what the feature branch adds compared to `main`. Which commands?BeginnerHalfway through a merge you realise you pulled the wrong branch. How do you back out?Beginner