Submitted by admin on Wed, 08/03/2022 - 16:19

This tutorial proposes a method that can be used to duplicate projects. This is very useful for using existing projects or template projects as a base for a new application.

Although a simple copy/paste from the project explorer seems to work, I've found that many paths are not updated and still refer to the source project.

Cloning an existing project mostly consists in:

  1. Duplicating the existing project folder
  2. Opening the new project into VSCode
  3. Performing some manual edit in project configuration files to change its name

In this tutorial, we will duplicate the blink project as a new my_project project.

1. Step #1: Duplicate the source folder

Using your OS explorer, navigate into your workspace folder and copy/paste the blink folder:

Copy the source folder

Rename that folder with the new project name my_project:

Rename the source folder

2. Step #2 : Clean & edit new project configuration files

Now open the my_project folder. If it is not done already, activate "Show hidden files":

Show hidden files

Delete the target folder (these have been produced during build).

To change the linked Git repository, you either have to

  • Delete the .git folder and initialize a new Git repository (which links your project to the Git repository of the old project)
  • Change the Git remote of the project

_Both of these solutions will be described in Git & GitLab part..._

Then, open the project in VSCode:

Open project in VSCode

3. Step #3: Search and Replace

Open the Search and Replace tab (Ctrl + Shift + F) and replace every occurence of the old name blink with the new name my_project:

VSCode Search and Replace

Validate the replace (VSCode Replace All or Ctrl + Alt + Enter).

You should be able to build/debug without problem since all the build options you have set in the source project have been preserved during the cloning operation.