Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

work on two branches on the same project in intellij idea

I would like to work on two separate branches in my idea project.

An easy solution would be:

Clone the git directory (a second time) in my project folder and checkout the git required branch. This is not working in idea, the git copy does is not recognized as git folder.

The repository is not in project root, current structure:

ProjectFolder/
ProjectFolder/gitRepository
ProjectFolder/gitRepositoryClone
like image 977
Ximi Avatar asked Nov 17 '25 09:11

Ximi


1 Answers

First, don't forget git worktree (presented here) is not a second clone, but a copy of the working tree, on a different branch, for the same initial repository.

Second, from this thread, one way is:

I have created a worktree from command line next to the main work tree / folder and imported it as a second module

So do create it next to, not inside, your project folder, then import it.

And:

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.

like image 125
VonC Avatar answered Nov 19 '25 06:11

VonC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!