How do you resolve git conflicts in yarn.lock

When multiple git branches modify the dependencies in a project that uses Yarn, it is likely to introduce a conflict in the yarn.lock file. It is not a good idea to delete and regenerate the yarn.lock file because this will probably cause several packages to be unintentionally upgraded. What is the best way to quickly resolve conflicts in this file?

Answer

Since Yarn 1.0 it’s easy because it has built in support for this scenario. Just run this:

$ yarn install

yarn install v1.0.1
info Merge conflict detected in yarn.lock and successfully merged.
[1/4] Resolving packages...

Now you only have to do git add yarn.lock && git rebase --continue