Here is the step by step solution to do it.
- Open Android Studio -> Import Project-> Select your project directory. (In above case “MyApp”)
Remember Select the directory which contains Manifest file otherwise new “direct import wizard” doesn’t
get triggered and android studio uses old import wizard. - Android Studio will create a copy of your project “MyApp_imported” with new directory structure.
- Copy your existing “.git” directory inside “MyApp_imported”
- Android Studio -> VCS -> Enable version control
This will make Android Studio use your existing repository for imported project. Though imported project has
different directory structure but git handles them pretty well.
You might want to also callgit add .
andgit add -u
in the root folder of the imported project to make sure all new files are added and existing file moves are detected by git. - Android Studio -> Changes
Review all files and commit. Git will automatically handle new directory structure and file history etc will not be lost. - Now you can share it on github/Bitbucket by
VCS-> Share it on GitHUb
Note:- For bitbucket you will have to install “Bitbucket plugin” for Android Studio.