Interview Prep/Git & GitHub/Branching and Merging Workflows

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 →

  1. Resolve package.json first (that is human-owned).
  2. Take either side of the lockfile, then regenerate it:
git checkout --theirs package-lock.json
npm install
git add package-lock.json package.json
  1. 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.

All Git & GitHub questions Roadmap: Git & GitHub

More on Branching and Merging Workflows