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!
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!
请先登录再写评论。
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.
HTH,
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.
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.
Here's basically what I've got:
My_unrelated_scripts/
|—script_1/
|—.git
|—script_1.py
|—script_2/
|—.git
|—script_2.py
My only goal is to be able to open and work on script_1.py and script_2.py, 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 script_1.py and script_2.py in the same PyCharm window, make some changes to both and then want to commit changes to script_2.py, 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.
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.
Currently there is no such option as 'Control repositories synchronously'. How do I achieve having two repositories shown in the 'Git' toolbar tab?
I have opened the second project in the same window, it has it's own git repository, but all I see in toolbar 'Git' is the git repository of the first project. It cannot see the repository of the second project, eventhough there is one and I use it through the terminal.
I wonder if PyCharm's notion of a project these days allows working with two git projects under the same roof, such that some paths of code belong in one git project and some in the other.
The motivating scenraio being that you can avoid comitting everything you do to the one project's core, while still being able to git manage what's not in that first project's core, to a second repository.
Of course an alternative common pattern is to use the first git project as a library in the second one, but then you can't commit changes to the library directly from the same PyCharm project view, rather you have to keep two PyCharm projects open and constantly pull and merge the library or somehow point at it locally without PyCharm messing it up when seeing the same directories from two separate PyCharm projects.
In short, what would be a safe way to work on a library git project and a git project using the library, concurrently, with PyCharm?
I think that in pycharm settings terms (under settings) Content Roots and Project Structure combined Directory Mappings under Version Control enable that kind of workflow these days.
https://www.youtube.com/watch?v=3iw90Rlvmvw
https://www.jetbrains.com/help/pycharm/content-root.html
https://intellij-support.jetbrains.com/hc/en-us/community/posts/8251455665682-Multiple-content-roots-Git-repo-only-shows-for-the-first-one
Using multiple content root allows you using the one git code project from the other through regular imports as if they were the same project, i.e. you don't have to install the one project as a library for the other one to use. And you can still manage them as separate git projects.
Of course the onus is on you to avoid duplicate module namespaces.
This is a good way for avoiding bloat on a project being developed and shared, while developing specific code on top of it which does not belong in the canonical project being shared and maintained ― fluently and with full version control for both of the layers.
So PyCharm does (seem to) support working on two git managed projects which have call relationships between them, under the same window pane of glass which is the PyCharm project entity.