Switch node_modules folder when I change git branch

北城以北 提交于 2019-12-10 12:53:20

问题


I'm working with two branches, master and feature-1

In the master branch I'm using a lib xyz@1.0

In the branch feature-1 I've installed a new version from lib xyz version 2.0

feature-1 was not merged yet on master branch, because it's not done. Then when I switch to master again I've to re-install the lib@1.0, and if I switch again to feature-1 I've to re-install the lib@2.0

What's the best workflow approach in theses cases?


回答1:


You do things well with git and each time you switch, you have to do your npm i.

But perhaps if you switch very often from one branch to the other, you should think about using git worktree introduced in some recent git versions and which permit to have another branch checked out in another folder (here feature-1) but sharing the same repository (perfect for this type of work flow!) .

That way you will be able to do the npm i once for each branch and work in parallel on each branch.

It's quite simple to use but I will let you have a look to the documentation.

Once you're finished, just delete the folder with the added workspace (but not the main one with the .git folder!)



来源:https://stackoverflow.com/questions/38905973/switch-node-modules-folder-when-i-change-git-branch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!