Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should i push the .yarn/cache folder to Github - Yarn2

Tags:

yarnpkg-v2

I recently upgraded to Yarn2 and added the following to my .gitignore

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

I still use nodeLinker: node-modules, however when I push my code, I am pushing the .yarn/cache folder with new files whenever I upgrade packages.

Should this folder be pushed to Git or just in my machine? Please advice.

like image 339
a2441918 Avatar asked Jul 23 '26 00:07

a2441918


1 Answers

The reason why .yarn/cache is not ignored is because you have the ! in front of it.

Yarn Berry (Yarn 2/3) stores your node_module's zip files in its cache. The Cache can be global in your system, and therefore - shared between multiple projects, or local. I assume in your case, that the cache is local and stored inside- <project_dir>/.yarn/cache

To change this behavior you can use enableGlobalCache: true in .yarnrc.yml.

Should this folder be pushed to Git or just in my machine?

Well, it's a trade-off.

Pros:

  1. Install time is faster, you don't need to download any package during fetch stage
  2. You can install your modules without an internet connection.
  3. Moving between branches is seamless.

Cons:

  1. Your repo gonna increase drastically. For each change you made in your packages, git will remember the entire history.
  2. Clone time increases
  3. It's irreversible (sort of). After you push it to master, you can't rollback unless you delete those commits entirely.
like image 134
Hasholef Avatar answered Jul 25 '26 17:07

Hasholef



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!