How do I use git worktrees in IntelliJ IDEA 2016.1?
Asked Answered
P

2

19

The newest version of IntelliJ says it has support for git worktrees, but I can't seem to find anywhere that says how to use it. I was expecting to see an entry in the Git Branches popup in the lower right, but I don't see it there.

I also don't see any descriptions in:
Blog post announcing the feature
What's new video

IntelliJ help and googling were also unhelpful

I'm using Git version 2.7.2.0, worktrees were introduced in 2.5

Podite answered 5/4, 2016 at 22:40 Comment(2)
Can it navigate in worktree if you create it manually with command git worktree add ...?Arbela
according to youtrack.jetbrains.com/issueMobile/IDEA-143404 it is still not fixed, maybe you should track it for more infoArbela
J
18

As far as I can tell, "support" means that when you open a worktree in IntelliJ, all the VCS functions work properly. Based on the comments in the Youtrack link provided by max630, you could not view diffs, view history, or commit changes before 2016.1.

With 2016.1, however, you can open the worktree as a new project and perform all VCS operations via IntelliJ.

It would be nice to have project settings shared for those of us that .gitignore them, but that does not appear to be supported currently.

I have been using the following workflow recently with success:

  1. git worktree add ../hotfix hotfix/1.2.3
  2. File -> Open in IntelliJ
  3. Manually copy all Run Configurations over to the new .idea directory (if necessary)
Jehoshaphat answered 11/4, 2016 at 21:40 Comment(2)
Have you found a way around manually copying the configurations?Sherborne
@Sherborne I haven't, but I haven't been using IntelliJ for the past couple years, as we've mainly switched to TypeScript from Java. :)Jehoshaphat
S
8

The most likely reason to hit this is that git worktree add uses absolute paths by default, so if you run it from a bash (Git For Windows' or WSL), the path will not be valid on windows' git:

C:\code\worktree-repo>git status fatal: Not a git repository: /mnt/c/code/original-repo/.git/worktrees/worktree-repo

You can fix this by updating the path in the worktree .git file (not a directory for worktrees!) to be relative:

C:\code\worktree-repo>type .git gitdir: ../original-repo/.git/worktrees/worktree-repo

You should also update .git/worktrees/worktree-repo/gitdir to be relative so windows git in the original repo knows how to find the worktree, but that is less important (AFAIK, it prevents git worktree prune from dropping it and from checking out the same branch in the original repo)

Stephanystephen answered 29/5, 2017 at 23:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.