6

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.

BuZZ-dEE
  • 6,075
  • 12
  • 66
  • 96
arunmmanoharan
  • 2,535
  • 2
  • 29
  • 60
  • Does this answer your question? [Committing .yarn directory to git when using yarn berry](https://stackoverflow.com/questions/62984576/committing-yarn-directory-to-git-when-using-yarn-berry) – BuZZ-dEE Dec 14 '21 at 14:30

1 Answers1

7

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.
Hasholef
  • 703
  • 3
  • 10
  • 17