Skip to content

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.

Cloning an Ionic 2 Application from GitHub

Learn how to clone from Github, specifically how to clone an Ionic 2 project. In this Ionic 2 tutorial you'll also learn how to install and run Ionic 2 on a separate machine.

Jan 10, 2019 • 3 Minute Read

Introduction

In this tutorial, I will go over how to clone an Ionic 2 project from Github and get it running on a new machine.

When you first create an Ionic 2 application, it creates a .gitignore file that ignores almost all folders except the src and resources directories. This leaves the basics to build the project. However, if you don't know how to run these files, your project will contain numerous errors and you will be unable to proceed.

The pictures show the contents of most projects after uploading to Github or to another git repository.

Setup

For this tutorial, you need to have set up the current versions of Ionic 2, Cordova and Node/NPM on the machine you are using. In case these tools aren't ready, please see the links below:

If you don't want to have to re-install all your plugins and platforms you could remove the directories from the .gitignore file. That way, they would be included when you git commit.

Let's say that you have cloned your repository to your machine, and now you have a project that does not work. There is a procedure you need to run to finish your project off. After this procedure, you will be fine, unless you add another plug-in or platform, at which point it will be added to the package.json file, and you will have to run the following commands again on the other machine to update the application.

The steps

  1. In CMD or Terminal, run git clone <your-repository-address-here> in the folder in which you'd like to contain the project.

  2. Now either open your application in your favorite IDE (that has a terminal window) or cd into the new cloned project directory through terminal.

  3. Next you will need to get all your node_modules back into your application. All these modules are based on your package.json file. You may want to look at your file if you are getting errors and if you see a ^ before any of the versions like, typescript: ^2.0.6, remove it to fix the error. Here is the command to run in terminal.

      npm install
    
  1. Once that is complete you should notice that you now have a node_modules directory in your project structure. Now you will need to serve the app. Run this command in the terminal.
      ionic serve
    

This will create your www folder and your build folder which are necessary for a project to be treated like an Ionic or Cordova project.

  1. Now you are ready to restore the state of your project. Use the following command:
      ionic state restore
    

This will restore the platforms and all the plugins you had installed based on your package.json file. Now you should see all the platforms and plugins that you had previously installed now in your project folder.

Conclusion

Now your project should be restored to the original creation state. Remember, you will need Ionic, Cordova, and Node/NPM installed on the computer you are cloning to in order to run this project.


Hopefully this guide erases some of the confusion behind cloning Ionic 2 apps via Github. Thanks for reading.

Happy Coding.

Todd Shelton

Todd S.

Todd Shelton is a lecturer at IUPUI's School of Informatics and Computing in Indianapolis, Indiana. He started his career as a Flex/Flash Developer making interactive media projects at an award-winning design/development company. After several years as a Senior Flash Developer, he transitioned to a Front-End Web Developer where he continues to use his expertise to do freelance projects for multiple clients making mobile/web applications. He has created and run two successful users groups in his local community where he helps new and seasoned developers learn the latest technologies or just understand the current technologies. The newest user group, Dev Workshop, hosts an annual conference for all things media in Indianapolis, Indiana.

More about this author