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:
- Install time is faster, you don't need to download any package during
fetch stage
- You can install your modules without an internet connection.
- Moving between branches is seamless.
Cons:
- Your repo gonna increase drastically. For each change you made in your packages, git will remember the entire history.
- Clone time increases
- It's irreversible (sort of). After you push it to master, you can't rollback unless you delete those commits entirely.