Multiple content roots - Git repo only shows for the first one?

Answered

I'm currently working on two related Python modules.

In Pycharm (Intel Mac, 2022.2.3), I've created a new project with existing sources for "Module 1".

I then go into: Preferences -> Project -> Project Structure, and click "+ Add Content Root".  I select "Module 2" as a second content root.  I then click off which directories are source files versus test files, etc.

All of this works perfectly well (Pycharm has no problem finding code), except with regards to Git.  The git features in Pycharm only "sees" the git repo for "Module 1".  For example, any changes I make in "Module 2", they don't show up in Pycharm under local changes as it doesn't "see" the repo.  The repo also doesn't show up in the other git related menu options (like "branches", etc.).

As an alternative, I've tried moving both of my Python modules into a subdirectory, and just adding that one parent directory as the only content root.  When I do this, Pycharm can now "see" both Git repos!  This seemed like the solution, except with this change Pycharm can no longer resolve local modules (as the parent is now one directory higher).

Is there a way to have Pycharm see the Git repos for multiple content roots?

0
5 comments
Hi, red could mean the directories are not initialized with VCS. Do you have `.git` directory in them? If not, try running `git init` against those directories in the terminal.
1

Hello,

Have you mapped both project roots in Preferences | Version Control | Directory Mappings?

0

Aha!  That was the secret sauce I was missing.  It's working great now!

0

Hello 

I have the same issue: I have a project with 2 external Content root. I have mapped the folders in Preferences | Version Control | Directory Mappings, but they appear in red (see screenshot below) and I cannot add the files from these external folders to Git.

What am I doing wrong?

Many thanks for your help

 

0

that was the issue indeed. Many thanks, it works perfectly now

0

Please sign in to leave a comment.