Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyCharm: multiple projects in same window, independent version 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.

like image 821
glarue Avatar asked Jul 09 '15 02:07

glarue


1 Answers

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

  1. To get things started, open PyCharm, then File | New Project and navigate to script_1.

  2. 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".

  3. 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.

  4. Use the Projects menu on the left-hand side to view the opened projects and, importantly, open any Python files from those projects.

  5. 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.

  6. 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.

like image 148
glarue Avatar answered Nov 18 '22 07:11

glarue