61

I upgraded yarn from v1.22.0 to v2.0.0-rc.29. It generated .yarn folder with:

  • folders: cache, releases, unplugged
  • files: build-state.yml

Should I add whole .yarn folder to .gitignore? Or maybe some nested folders in there like .yarn/cache?

Also, what to do with .pnp.js. Do I commit it, or add to .gitignore

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Alexandr Panteleev
  • 715
  • 1
  • 5
  • 9

1 Answers1

82

See the Questions & Answers section of the documentation. It has changed several times, so for the most up to date answer just click that link!

But in the StackOverflow spirit of "no link-only answers" here's a snapshot:

Which files should be gitignored?

If you're using Zero-Installs:

.yarn/*
!.yarn/cache
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions

If you're not using Zero-Installs:

.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions

Note that, of the paths you mention, only .yarn/releases should not be in .gitignore.

Matthias
  • 13,607
  • 9
  • 44
  • 60
Thomas
  • 174,939
  • 50
  • 355
  • 478
  • 3
    UPD: answer is outdated. Check Q&A section, mentioned above. – Alexandr Panteleev Apr 10 '20 at 20:43
  • 4
    @AlexanderPanteleev Thank you, updated. That's what you get for adhering to StackOverflow policy of "no link-only answers"... :( – Thomas Apr 11 '20 at 07:11
  • 1
    "Which files should be gitignored?" Simple: Anything that's generated as part of the build process. Ideally, you only check in what you modify yourself. – cmaster - reinstate monica Apr 11 '20 at 07:23
  • 2
    @cmaster-reinstatemonica No, that's too simple. For example, `yarn.lock` is never modified directly by the user but should be checked in nonetheless. Same, apparently, for the `cache` (?!), `releases` and `plugins` subdirectories of `.yarn`, which are explicitly un-ignored above, despite probably never being hand-edited. In general, if a tool creates or changes files that the user doesn't directly care about, documentation like this is necessary to decide which of those files should be checked in and which should be gitignored. – Thomas Apr 11 '20 at 08:04
  • 4
    Pro tip: if you activated [@yarnpkg/plugin-node-modules](https://github.com/yarnpkg/berry/tree/master/packages/plugin-node-modules), and can see a "node_modules" folder in your project, you're not using the zero-installs approach, even if you can still see the ".yarn/cache" folder. – Paul Razvan Berg May 19 '20 at 22:34
  • 3
    How do I know if my project is Zero-Install? Installed using from [yarn installation page](https://yarnpkg.com/getting-started/install) but it doesn't tell me if it's a Zero-Install or not. – arahpanah Jan 17 '21 at 13:50
  • How can i know if using zero installs? – carlosbf Jul 05 '21 at 10:37
  • 2
    If you have to ask, you're _not_ using Zero-Installs. – Thomas Jul 05 '21 at 10:47
  • This is overly complicated – Sang Mar 13 '23 at 16:57
  • @transang Please direct your complaints to the Yarn developers. This answer is just quoting their official documentation. – Thomas Mar 14 '23 at 09:18