1

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 !

2
  • 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. Commented Feb 1, 2018 at 16:37
  • 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. Commented Feb 1, 2018 at 19:14

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Hi, thank you for your answer, I'm not keen on tracking the node_modules directory, I don't want to uselessly overload the repo. I haven't heard about worktrees, I'm gonna check it out, thanks ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.