Git branch and venv workflow

What is a suitable workflow for using venv with different git branches for the repo? For example, I’d like to be able to run Main, Develop, or Feature branch in a virtual environment. The branches are fairly similar with small differences.

Found a discussion at git - Integrating Virtualenv with two GitHub repositories - Stack Overflow

I’ve never heard of something like this, so don’t know any recommended workflow for this specifically. If I wanted this, I would probably created different venvs under a ‘.venv’ directory, each venv named after a branch.
However, I don’t understand why you’d want separate venvs for separate branches. Could you elaborate on what you are trying to achieve?

Out of curiosity, why branches?

For example, the Development branch is setup in a venv. The recommended workflow is to develop each feature in a new branch. How can the feature in a Feature branch be tested in a venv?

Are you suggesting from within the venv do git checkout [branch] to test different branches?

Yes, it’s a good practice to develop features in separate branches. However, you don’t separate venvs for that as venvs are primarily used for dependency management. One venv per project is typically enough.

If you are concerned with automated tests for multiple python versions, I’d recommend you to check out tox tox

1 Like

If you install your project into the venv in develop (editable)
mode, then its files will be mapped in directly. When you change
branches, the differences in local files for your project are
automatically reflected in the venv that way without needing a
separate venv or reinstallation.

1 Like


  • Use a single venv for the repo.
  • In the venv install your package you are developing in editable mode (it will create symlinks to your source directories). For example install package present in the current directory:
    pip install -e .
  • Only if a branch needs different dependencies (new - incompatible version of a library) then create a new venv for the branch and install your package again there.
1 Like