'How to move a module from a project to its own separate project in intelliJ or git?

I have a gradle project with a structure like this:

project2
 -submod1
 -submod2
 -submod3
 -submod4

I want to move submod2 to its own gradle project with its history as well. Is there a way to do it in IntelliJ or using git commands?

I already have an empty repository let's say called project2.

Also I want to achieve this by only making changes locally, so without pushing anywhere.

Thanks a lot for the help :)



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source