How to change git directory in Android Studio

I recently created a new project in Android Studio and started working on it. After writing some activity classes I added git integration to my project. But to my surprise when I pushed the project, It pushed one directory higher than my project’s root dir. It contained all the projects I had worked on. I had to delete the repository and create a new one.

I even tried to change the directory from Android Studio > Preferences > Version Control. But it returned an error saying “invalid vcs root mapping“. Even rebuilt the project, did invalidate cache and restart but no help. So what’s wrong here?

Android Studio Version Control Settings VCS root

The problem is that Android Studio had put the .git to the wrong directory. I don’t know why and how, but if something similar happens to you, follow the instructions below.

Move .git from wrong directory to Project directory

  1. Open Terminal in Android Studio (with your Awesome Project open).
  2. Go to the “wrong” directory where .git is located (See that in Version Control settings).
  3. Run this command.
    mv .git /MyAwesomeProject
  4. Go back to Version Control settings (Android Studio > Preferences > Version Control) and add your project directory and apply the settings.
  5. That’s it. Now commit (and push) your project.

One reply on “How to change git directory in Android Studio”

Leave a Reply

Your email address will not be published. Required fields are marked *