The scenario: I have a locally cloned github repo with multiple branches. Each branch needs potentially different dependencies.
The question: I would like to switch between these branches as I work and therefore would like multiple pipenv
virtual environments (one per branch). How can I achieve this, given that pipenv
by default associates a single virtual environment with the project root folder?
Check out each branch into a separate directory (e.g., using git worktree
). Because each branch would have a separate directory, pipenv
would work without any additional changes.
Assuming that you're currently in your work tree (let's say on the main
branch), and you have additional branches named branch1
and branch2
, that might look like:
$ git worktree add ../branch1 branch1
$ git worktree add ../branch2 branch2
Now you main
checked out in your current directory, branch1
checked out in ../branch1
, and branch2
checked out in ../branch2
. You can cd
between these directories and work on them like normal, and pipenv
will do what you want since each branch is now in a separate directory.