58

We are migrating from Mercurial to GIT.

With Mercurial we have separate repositories compared to one repo with separate branches in GIT.

Thus with Mercurial it's straightforward to open two separate repos in two separate instances of your IDE. How can you do this with GIT as there is (I believe) only one branch current at a time in a GIT repo?

Note: this similar ticket refers to opening two branches in the same IDE. The difference with this question is we're happy to open them in two separate IDE instances. Though I'm guessing the answer is the same - you can't do it.

Community
  • 1
  • 1
Marcus Leon
  • 55,199
  • 118
  • 297
  • 429
  • 1
    Possible duplicate of [How to open 2 Visual Studio instances, with same Git projects and different branches](https://stackoverflow.com/questions/36687536/how-to-open-2-visual-studio-instances-with-same-git-projects-and-different-bran) – Ali Karaca Mar 15 '19 at 12:55
  • 1
    https://stackoverflow.com/questions/36687536/how-to-open-2-visual-studio-instances-with-same-git-projects-and-different-bran – S K Mar 19 '19 at 21:42
  • 2
    It is possible, using `git-worktree` : "Manage multiple working trees". Docs at: https://git-scm.com/docs/git-worktree. Some related SO links, mentioning worktree as a solution: [How to open 2 Visual Studio instances, with same Git projects and different branches](https://stackoverflow.com/questions/36687536/how-to-open-2-visual-studio-instances-with-same-git-projects-and-different-bran), and [Multiple working directories with Git?](https://stackoverflow.com/questions/6270193/multiple-working-directories-with-git). – SherylHohman Jan 13 '21 at 16:20
  • Oh...these SO links are the same links that the above two comments suggested. Well, the Docs link is new, and title of the second link is now visible. – SherylHohman Jan 13 '21 at 16:23
  • Does this answer your question? [How do I use git worktrees in IntelliJ IDEA 2016.1?](https://stackoverflow.com/questions/36438333/how-do-i-use-git-worktrees-in-intellij-idea-2016-1) – user7610 Apr 02 '23 at 16:36

2 Answers2

87

You are correct: there is only one active branch at a time. The best you can do is to clone the repository twice on your local machine into two different directories, and then simply open up the appropriate directory in each IDE instance.

David Deutsch
  • 17,443
  • 4
  • 47
  • 54
16

After making the two clones as David Deutsch suggested, I recommend picking one as primary and creating a symbolic link to the .idea directory from the secondary clone to the primary clone. This way you will have the same config in all clones.

ln -s primary_clone/.idea secondary_clone/.idea

This assumes you use the .idea project config format and that you do not check config to the repository (in that case you are obviously all set from the get go)

it mostly works, only sometimes Idea prompts you with dialog box to reload other projects if you change some setting in the currently active one. You can refuse, though.

user7610
  • 25,267
  • 15
  • 124
  • 150
  • 6
    Great idea. In Windows you would use the **mklink** command like this: `mklink /J "C:\Clone\.idea" "C:\Original\.idea"` – Ionian316 Jun 05 '18 at 19:12