Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Solve `yarn.lock` or `package.json` conflicts without losing your mind

NOTE: This guide is ONLY for devs who don't want to edit their yarn.lock file by hand. If you don't care about that please carry on.

So you've pulled the latest master

git checkout master
git pull

And checked out your favorite branch but when you try to merge master into it...

git checkout my-awesome-feature
git merge master

Uh-oh! Both your fave branch and master have changed stuff in yarn.lock

CONFLICT (content): Merge conflict in package.json
CONFLICT (content): Merge conflict in yarn.lock


Sure you could probably fix the package.json conflict "by hand" but the lockfile should not be touched 💩

All sorts of naughty thoughts might be going through your head at this point including conflict fix branches, merge stategies or even god-forbid... a rebase⬅️🚗💨

Does GIT support a type L phase discriminating amplifier

But fear not my troubled friend, there's no need to go that far, here's how you can fix this in 3 easy steps:

  1. Write down the exact package names and versions that your branch added/removed/upgraded (eg: left-pad@^1.1.3).
  2. Checkout and stage package.json and yarn.lock from master.
git checkout --theirs package.json
git checkout --theirs yarn.lock
git add package.json yarn.lock
  1. Re-apply the packages you wrote down in step 1 (eg: yarn add left-pad@^1.1.3).

Now the conflicts should be all gone and you're free to go on your way (commit the merge or fix other unrelated conflicts).


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment