1
votes

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 !

1
Are you going to eventually merge both the Elm and Vue branches into master, or are they going to stay separate forever? If the latter, then you should either put them in separate directories (e.g. elm, vue) with their own package.json and node_modules, or into separate repos. - Jordan Running
Hi, thank you for your answer, the master branch is supposed to be the next production code, so yes, one of these branches will eventually be merged into master, but not necessarily forever. - Nabil Ghedjati

1 Answers

1
votes

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.