Wednesday, February 12, 2014

Android Studio: How to push your code into GIT repo?

The target of this post is to describe detailed steps on how to push your code from Android Studio into GitHub.

Version of Android Studio: 0.3.6


  1. Assuming that your code isn't under version control. So the first step is to add your source code to VCS (Version Control System) which is Git in my example. So you have to enable Version Control Integration in your project by pressing "VCS -> Enable Version Control Integration"
  2. Enable VCS integration

  3. Choose Git as your version control system as indicated here:
    choose Git as your version control system
  4. Now all of your files will be turned into Red color which means that they are not added to VCS yet as explained here 
    Non-versioned Files
  5. Add all your project files to version control system as follows: 
    Add to VCS
  6. Now all files should be turned into green color as explained here:
    Files status change after adding to VCS
  7. Files are ready to be committed to your local repository:
    Commit to local repo
  8. Prepare you commit message then press commit; In our example it is "Add initial code version"
    Add commit message
  9. You should a notification green window message as indicated below:
    Commit Green Message
  10. You are almost ready to commit but you have to apply recommendations of IntelliJ and ignoring some unnecessary files by adding them to .gitignore file. I will add any iws file inside .gitignore
    Change gitignore file
  11. Again add Commit message
    Commit message for .gitignore
  12. Assuming that you have a valid Git repository on GitHub, In our example it is https://github.com/Wael-Showair/test
  13. Download and install Source Tree application from the following website.
  14. In Source Tree program, File -> Open and navigate to your project folder. Don't forget to cancel bookmark creation as well.
  15. In Source Tree program: Repository -> Add Remote, you should see Repository Settings window
    open remote repository in Source Tree
  16. Fill in your GitHub repository fields as follows:
    Fill in data of your remote repository
  17. Back again to your Android Studio, Synchronize button (rounded blue arrows) then push your local repository to GitHub repository as follows:
    push you code to GitHub repository
  18. Choose the most updated commit comment then press push. Don't forget to tick below checkbox to push your code to specified branch. In our example I renamed it from "master" to "newBranch". You should have get a green text message indicating your successful commit into GitHub repository
  19. Successful notification of repo push
  20. Check your GitHub repository url, it should indicate you the code with the respective branch name that you specified