Support for git worktree
Answered
According to this blog post https://blog.jetbrains.com/idea/2016/02/intellij-idea-16-eap-improves-debugger-and-adds-git-worktree-support/ intelliJ has added support for git worktrees. However I cannot find any documentation on how to use it inside intelliJ.
As a workaround I've created a worktree from command line next to the main work tree / folder and imported it as a second module but that doesn't seem the right way... or is it?
Please sign in to leave a comment.
> As a workaround I've created a worktree from command line next to the main work tree / folder and imported it as a second module but that doesn't seem the right way... or is it?
Yes, it is the right way. Support mentioned in the blog is the ability to handle worktree as a git repository correctly. It does not imply the ability to create worktrees from IDE.
Fair enough. What is the recommended approach: as a subdirectory of existing module, or on the same level next to the original?
Either way should work if I understand the question right.Just make sure to register mappings at Settings - Version control
thanks
I am using WSL Bash git with Windows IntelliJ 2018.2. This normally works perfectly, but I ran into an issue with worktrees. Sharing my adventure here in case anyone else is running down a similar path...
From bash, I created a git worktree in another directory, but when I tried to load it in IntelliJ, it complained that VCS has no root.
In the worktree directory is a .git file that points to /mnt/c/Users/myusername/src/myproject/.git/worktrees/mybranch. The problem appears to be that windows git (apparently used by IntelliJ) could not parse the posix style path. I fixed it by editing the .git file to point to a relative path, ../myproject/.git/worktrees/mybranch. Git was able to handle this (both DOS and Bash versions) and IntelliJ's git integration also worked after this change.
Dmitriy,
Does it make sense to keep a separate project for each worktree, (and open them in separate IDEA windows, if necesary)?
I think this question would be more relevant for multi-module projects, where creating (modules * branches) is impractical...
> Does it make sense to keep a separate project for each worktree
I believe this is the right thing to do while putting worktree to the same project is not. Checking out worktree inside your project folder is kind of duplicating the source code, and the use-case, in general, is not clear, unless there is some very specific setup.
E.g. in IntelliJ project we do use worktrees, and they are usually checked out in a separate folder and opened as a separate project.
Dmitriy Smirnov how do you folks handle non-trivial project configurations? e.g. I have a project with multiple sub-projects (each subproject being its own repo), the projects are big enough that I regularly have to increase the inotify watch limits or pycharm misses branch changes (or a subset thereof).
I'm looking into using either clones or worktrees for that, but moving the project configuration around seems difficult.
Using git worktree for the first time now in 2024. I experienced the same issue as @... and his hint with editing the .git file in the worktree and using a relative file path fixed it for me. Now I am able to commit my changes via PHPStorm once again. Thank you.
Dmitry D Smirnoff Is there a plan to address this? caught me out today using phpstorm.
Hi,
We currently do not have plans. please see: https://youtrack.jetbrains.com/issue/IJPL-72834/Git-integration-does-not-work-with-work-tree-when-work-tree-reference-is-absolute-path-in-WSL2 and feel free to comment and vote up.