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.
After some investigation, and the help of Fred Reimer on the Jetbrains forums, I believe the answer to this question is "yes, multiple projects with independent Git repos can be managed within a single window in PyCharm". Here is a toy example to illustrate one possible implementation:
Say we've got two separate projects under Git in a shared scripts directory:
My_unrelated_scripts/
|—script_1/
|—.git
|—script_1.py
|—script_2/
|—.git
|—script_2.py
To get things started, open PyCharm, then File | New Project
and navigate to script_1
.
Assuming we've already got some code and a Git repo going, PyCharm will ask "Would you like to create a project from existing sources instead?" - choose "yes".
Repeat step 1 for the script_2
directory, and this time PyCharm will also ask where we would like to open the project, in a new window or the current one. Choose "Open in current window", and check the "Add to currently opened projects" box. Repeat this step for any additional projects.
Use the Projects
menu on the left-hand side to view the opened projects and, importantly, open any Python files from those projects.
Once multiple projects/files have been opened, we can also check the overall project dependencies to make sure we aren't unnecessarily complicating the relationships between our scripts. Go to File | Settings | Project: <first_opened_project> | Project Dependencies
to view each opened project and its associated dependencies. Uncheck all of the boxes which associate projects that are independent.
To avoid having PyCharm apply Git actions (branch
, merge
, etc.) to all open projects, we can go to File | Settings | Version Control | Git
and ensure that "Control repositories synchronously" is unchecked.
Performing Git actions separately for each project simply requires using VCS | Git | Commit File
with a particular file in focus. Alternatively, the dedicated VCS Commit Changes
button (hotkey Ctrl-K on Linux/Windows) can be used, but in that case we must deselect those files with changes which we don't want to include in the current commit (in the top section of the "Commit Changes" dialog window), as PyCharm will default to include all changed files currently open in the window.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With