Nabil Ghedjati
Nabil Ghedjati

Reputation: 11

Create specific node_modules directories for different git branches

I've done few searches before posting but none of them helped me.

I hold a git repository for my personal website, and I have a small problem when checking out one of its branches. There are 3 branches for different tools or frameworks : the former master branch, which acts as the current version of my website, & the Elm and Vue ones, that I'm working on at the same time. Each of these branches contains a package.jsons file and so a node_modules directory. My problem is : after checking out a branch, I have to 'yarn install' my packages to run the dev mode or build the app (with webpack), because of all the conflicted packages hosted in the same directory on different versions I guess.

It's a bit tiring to reinstall the required packages each time I checkout a branch. Moreover, I have then to commit the updated yarn.lock file.

So I am wondering if there is a way to create a specific node_modules folder or sub-folder, one for each branch, in order to have "scoped" directories. Or should I better separate this repo in 3 repos ?

I hope I am clear about this problem.

Thanks for reading !

Upvotes: 1

Views: 549

Answers (1)

phd
phd

Reputation: 95038

You can commit node_modules so git will switch them on git checkout.

Or you can create separate worktrees. Checkout different branches in different worktrees and don't switch branches afterwards.

Upvotes: 1

Related Questions