I had an old Android project that I think I had started in Eclipse or some old version of Android Studio. Anyway the project structure was completely different from how Andr
Rename your current project folder (the new one you want to put on GitHub) to something like MyProjectBackup
.
In Android Studio, go to File > New > Project from Version Control > Git. Then log in with your GitHub username and password and select your old project's repository name from the list of your GitHub repos. Continue through the import wizard and you should end up with your old project in Android Studio. (Now, for example, your old project is in MyProject
and your new project is in MyProjectBackup
).
Manually delete everything except for .git
and .gitignore
(and maybe the readme and license) from your MyProject
project folder. (I had tried git rm -r *
but I was getting errors.)
From the command line in your MyProject
folder run
git add -u
git commit -m "deleting old files before adding updated project"
This will update the tracked files in the working tree for all the manual deletions you just made.
Copy in all your new files from MyProjectBackup
. Then run
git add .
git commit -m "new updated project"
git push
Now your new project will be in GitHub and the old project's commit history will still be available.
Helpful reading