Multiple projects, same window, independent git control

I use PyCharm to work on relatively short, purpose-built scripts under local version control with Git.

Until recently, I did not use version control at all. My preferred method of working was to open multiple files in tabs in the same PyCharm project, and treat them all independently.

Is there a way to use script-specific version control for multiple projects/files in the same PyCharm window? I don't fully understand PyCharm's "project" paradigm, and haven't found a way to open multiple projects in the same window under independent version control repos.

Thanks for any/all help!
Comment actions Permalink
You certainly can!  I'm not sure what platform you are on, but on my Mac I just create a new project and point it to the existing Git directory.  It says there is code already there, and asks if I want to create a project using the existing code.  Say yes, and it then asks if you want to open the project in the same window, and add it to the existing project, replace the existing project, or open it in a new window.  I usually have 5 or 6 projects open in the same window at the same time, because they are all related but belong in different repos.

Once you have multiple projects open, it asks if you want to manage the branches synchronously or not.  That means if you change to a new branch in one, it can sync and change to that branch in all of your projects.  Or, you can manage them independently, which sounds like what you want.  I do that also.  If you need to change this, go to Version Control in Preferences and under Git uncheck the "Control repositories synchronously" option.

Comment actions Permalink

Thank you so much for the detailed answer. It was difficult to find out specifics on this through Google-foo alone.

I'm on Linux, but it seems like the system is laid out the same. Just to make sure I understand, adding multiple scripts from multiple directories with multiple discrete Git repos to the same PyCharm project doesn't necessitate any kind of Git cross-talk, right? Unless, as you mention, synchronous Git management is enabled. I suppose I've been somewhat trepidatious about combining multiple files into one "project" for fear the project architecture would somehow merge things together, but based upon your answer it appears I can in fact use it just as I was hoping.
Comment actions Permalink
Ah.  A little bit of misunderstanding here.  The different git repos would be in different PyCharm projects.  I don't think you can add in multiple directories with different git repos in the same PyCharm project.  It does however support adding multiple PyCharm projects in the same view.  So, like I said, you can start with one project, and then Open another project and add it to the existing project.  When you come back to PyCharm the opening window gives you a list of projects.  Mine is like:

salt, pillar...
botocore, boto3...

etc.  So you can open them all up together again.  But, like I wrote, they are separate PyCharm projects.  I'll have to test only having one project and multiple git repos in it, but I suspect that is not supported...

And no, there's no crosstalk between the projects, although PyCharm supports managing the repos concurrently if you want.  When you commit, you can select what you want to commit independently, and when you push you can select which remote repos to update.
Comment actions Permalink
I'll try to be a little more specific in my setup, so you can disabuse me of my ignorance more effectively. :)

Here's basically what I've got:


My only goal is to be able to open and work on and, which are completely unrelated, in the same PyCharm window, and to be able to commit changes in either to the appropriate Git repo without involving the other one. Perhaps this is what you were saying, but for example if I open and in the same PyCharm window, make some changes to both and then want to commit changes to, PyCharm defaults to committing the changes in both files simultaneously.

Is all that would be required for my desired setup be to simply select only the scripts I want to commit? I guess I just want to be sure that, since PyCharm seems inclined to group the scripts for actions like commit, there aren't any other ramifications of opening multiple projects within the same window.

Thanks for the continued guidance.
Comment actions Permalink

  • choose create new project and specify script_1 directory as the location

  • It will tell you the directory is not empty, and ask "Would you like to create a project from existing sources instead?"  Choose yes.

  • Then on the file menu select New Project, and specify the directory for script_2.

  • Again, it will ask if you want to create a project from existing sources.  Choose yes again.

  • Then it will ask "How would you like to open the project?" and you have the option for "Open in new window" or "Open in current window" and a checkbox for "Add to currently opened projects."  Select Open in current window and make sure the checkbox is checked.

You now have two projects in one window, and if "Control repositories synchronously" is unchecked in preferences Version Control Git you can control the git repos separately.  However, even if this is checked it will not "mix" the git repositories.  They are separate entities.  What sync means is that if turned on it will do the same git "stuff" to both repositories at the same time.  "Stuff" refers to things such as creating a branch, checking out a branch, etc.  This may make sense for some use-cases, but in your example it would not, so I would make sure it is unchecked.

You may also want to go under Project and Project Dependencies and uncheck the project dependencies.  I'm not sure exactly what this does, but it makes the projects dependent on each other, and that doesn't sound like the appropriate behavior for your situation.

Hopefully that clarifies things.
Comment actions Permalink
Fred, many, many thanks for your replies. Sounds like everything will work great.

Please sign in to leave a comment.