30

I want to run some tests in my project but I do not want to affect the original code, and I wanto to clone the project so I can run tests there

Does anyone know how to clone a project on IntelliJ Idea 11?

ocespedes
  • 1,233
  • 4
  • 14
  • 27
  • Just make a copy of the project directory. Unless you want to commit from the "clone" and are using an annoying VCS that keeps a global registry of checkout locations (like TFS) this should work. – millimoose Jun 11 '13 at 01:13

6 Answers6

33

Using your operating system File Explorer tool, just copy and paste the entire project directory somewhere new. All of the configuration should use relative paths by default.

If your IDEA project is .ipr based, then delete the new .iws file before opening the project. If your IDEA project is .idea directory based, then delete the workspace.xml file before opening the project.

Jen S.
  • 4,106
  • 4
  • 35
  • 44
  • 3
    Just wanted to add that you should also delete any version control directories like `.git` so you can commit your work to a new repository, if you want. – The Unknown Dev Jul 01 '17 at 18:15
  • You might want to rename the new project's package if it's not the same as the old project's. – Matthew Mar 16 '18 at 15:28
  • IntelliJ latest versions allows project duplication within the IDE: https://stackoverflow.com/a/61665059/9567003 – Helder Daniel Aug 28 '23 at 11:59
6

If you want to copy and rename the project too, like I wanted to clone a project in order to use it with a newer version of IntelliJ.

  1. Copy the whole directory to a new location, for example on Linux:

    cp -r myproject new/location/

  2. To rename the project:

    2.1. rename the project folder (e.g. mv myproject newproject)

    2.2. get into the new project folder (e.g. cd newproject) and edit the .name file with a text editor.

Open the new project now in IntelliJ (you may want to remove the workspace.xml if you don't want to keep the open file history - I kept it) and enjoy your new project!

ksymeon
  • 600
  • 6
  • 6
  • 1
    If you're using gradle, you may also want to be sure to check and change rootProject.name in settings.gradle. – bbarker Jul 02 '15 at 20:02
2

For copy with rename I had to do one more step to get it to stop referencing the old module name. That was to right click on the module in the project pane and do Refactor > Rename ( or do Shift + F6 ) to rename the module.

This was for IntelliJ IDEA 2016.3.3

yokeho
  • 177
  • 1
  • 7
2

I had a gradle project and the provided answers did not work. The project did not have a structure in IntelliJ and I did not see the source files.

The following worked:

  1. Export project (Export to zip file)
  2. Move the zip file somewhere new
  3. Unzip
  4. With IntelliJ, import as a new project with "open".

Better Solution of course:

Have it in a git directory, make a "test-branch" and try whatever you want to try.

1

Apparently the accepted answer doesn't work anymore with current versions of Idea and the many derived IDEs (I tried this with PHPStorm). The problem: most of the config files are located in the .idea subdirectory of your project, but the file .idea/workspace.xml also contains the ProjectId, and that should of course be unique. So, if you copied the project directory manually, the easiest fix is to change the ProjectId - from what I have seen you can enter any alphanumeric string, e.g. "ProjectId123".

As far as I can see the main settings that are stored under the ProjectId are the workspace settings, under ~/.config/JetBrains/[IDENameAndVersion]/workspace/[ProjectId].xml. This file mostly contains the open editor tabs (with paths relative to the project directory) and the tool windows, so if you copy the project directory, you will always have the same editor tabs open in both projects (containing the "same" files, but from the respective project). If you want to avoid opening all files and setting up the tool windows, you can copy the old [ProjectId].xml file to e.g. ProjectId123.xml (using the ProjectId that you entered earlier).

rob74
  • 4,939
  • 29
  • 31
  • yes,you are right, I found it , i clone a project , but they alway use same bookmarks , because bookmarks are stored in /workspace/[ProjectId].xml , and 2 project both use the same xml file – qiz_newbie Aug 17 '22 at 19:36
0

After Copying your existing Project to a new folder don't forget to mark your src directory as Source directory. You can do this under Project Structure | Modules.

Balaji Radhakrishnan
  • 1,010
  • 2
  • 14
  • 28