Android Studio Git Clone Push Pull Repository

For personal development in Android Studio, using BitBucket as remote repository here’s my VCS workflow using Git.

Android Studio VCS setup for untracked project:

  • VCS -> Import into Version Control
  • Create Git Repository
  • Add files & directories to track in Git, using File Explorer (left window)
    • Since these are personal private projects, git add all Android Studio files except:
      • /build
      • /app/build
      • External Libraries (these will be pulled in via Gradle upon sync/build)
    • Create a .gitignore file in the project root.  Add lines for /build and /app/build
    • VCS (menu) -> Commit Changes
      • this performs an initial commit, now we’re ready to add a remote repo & push
  • Create a repository at BitBucket, GitHub or wherever
  • get address of repository from remote git repository (top right corner HTTPS URL of repository overview page)
  • in Android Studio Terminal (bottom left in tools window), run the following command (replace username & repo-name with values from your repository)
    • git remote add origin https://[email protected]/username/repo-name.git
    • git push -u origin –all
  • Repository at remote location is now synced with local project.
  • For future commits, do Commit and Push to keep remote repository up-to-date

Clone Android Studio project from remote repository

  • From the remote repository web interface, Fork the repository with a new name
  • From Android Studio startup dialog choose:
    • Check out project from Version Control
  • Choose Git for BitBucket, Github for Github
  • In the Clone Repository dialog, Grab the forked repository URL from the web interface of Github or BitBucket (Overview page), paste into Vcs Repository URL field
  • Change Parent Directory if needed (usually not required)
  • Enter a directory name of your choosing
  • Click Clone button
  • Android Studio will pull files and clone the repository, ready for work
  • You’re done, add / edit / Commit + Push as usual
  • Likely you’ll get a dialog asking to add project-name.iml file.  I add it.