Git can be used easily with Android Studio. (We will not discuss in detail about the git commands in this tutorial. Please check Git Tutorial 1 and Git Tutorial 2 if you find any problem) . So,in this tutorial, we will learn how to create , commit and push a new project to github and pull an existing project from github using Android Studio.
1. Check git is installed or not on your System :
a) Open Android Studio and create a new Sample Project.
b) Click on File->Settings -> Versioin Control-> Git
c) Click on “Test” near “Path to Git Executable”
if “Git Executed successfully” message is displayed it means that git is already installed on your system.
Step 1 : “git init”
VCS -> “Enable Version Control Integration” -> and select “Git” from the dropdown list as shown above
Step 2 : “Git remote add origin”
For this step , we should use “git bash” or if you have installed git integrating with command prompt , we can use it from Android studio terminal.
a) Using android studio terminal :
Step 3 : “git add” :
VCS -> git -> Add
(Note that you should select your project before clicking “Add” like below )
Everything added newly to git will be marked with green.
Step 4 :
If you add any new files in future, Android studio will ask to add these files to git or not as :
Step 5 : “git commit” :
Click on VCS-> “Commit Changes”
write one commit message and click on Commit . Now all files will be back to its normal color.
If you make any new changes to an already committed file, its color will be turned to blue.
i.e. Red - File is not added to git
Green - File is added but not committed yet
Blue - New changes is added to a file that is committed to git already
Step 6: “git push” :
VCS -> Git -> push
this will push your changes to git server repository.
Step 7: To clone a project :
VCS ->Checkout from version control -> click github or git and paste your git url of the repository that you want to checkout :) . Android studio will sync automatically if any dependency need to be resolved.