A blog on using Git in Android Studio

jai surya
Developer Community SASTRA
5 min readNov 17, 2022

--

GitHub is an Internet hosting service for software development and version control using Git. It provides the distributed version control of bug tracking, software feature requests, task management, continuous integration, and wikis for every project. By integrating your current project with the git using the Android studio, you can gain instant access to shared projects, quick upload of your Source code to repos, and much more with the built-in initial commit option.

To begin with, make sure you have installed the latest version of Android Studio with the latest SDK and Gradle version.

Install Git on your computer by clicking here.

  1. Open Android Studio with a new project and a template Activity which you are compatible with.
Here I chose Empty Compose Activity

2. Look for the VCS button in the toolbar and select the “Share project on GitHub” option.

Share project on GitHub

3. After selecting the share project on GitHub button, you will get this secondary window asking for a version control system to associate with BlogonGit3 . Here, select Git as your preferred version control system and click on OK.

Enable the version control Integration

4. To confirm your integration with Git, a confirmation message will appear at the bottom, commenting that a git repository has been created successfully in local storage.

Look in the bottom left corner of your Android Studio window

5. Also, to double-check , carefully notice that all the file names on the Project tab will turn orange. The VCS button on the toolbar will disappear, replaced by a new button “Git”.

AS window after successfully integrating with git

6. Following successful integration with git6, upon completion of the coding segment in the project, the project file can be shared on GitHub by clicking the “Git” icon on the toolbar and selecting “GitHub>Share” project on GitHub.

The project should be shared on GitHub7.

7. In the newly popped window, assign a name to the repository and choose the remote as its origin. On completion of installation and set up of GitHub, in the “share by” box, the username is displayed. [Illustration 9]. If you can see your username, go to step number 9. Otherwise, proceed to the next step.

Once you’ve completed all the buttons, click the Share button.

8. If there is no username on the ‘share by’, it means the account is yet to be connected with the installed GitHub on the computer. To connect, give the share in the ‘Share project on GitHub’ window, and consequently an ‘Add Account’ window will pop out. Here it will ask a token for the GitHub account. You can acquire one for your account by simply clicking on the generate button, or click here to open the official website to generate a token for yourself. To integrate your account with the installed GitHub application, copy the token, paste it in the box, and click “Add account.”

Paste your token in the box 9

9. After successfully adding your account to Git, you can share your repository directly from Android Studio to your GitHub account.

Click “share” after the successful addition of your account.

10. Now it’s time to make your initial commitment — the selection of files that must be posted on the repo. Select all the required files and hit the “add” button to directly send all the selected files to the destined repo.

Initial commit

11. Here is your confirmation popup message on the right bottom corner to announce that the commit was successful.

Commit confirmation

You have now successfully merged Android Studio with GitHub and shared your project files with your account through a repository. What if you have to make some changes in the coding part ? You must update your repository by committing once again and pushing the commit to your repository. It is just like replacing the existing project files with the new ones.

12. Your project is now under version control and shared on GitHub. You can start making changes to commit and push. Notice that after I made the change, the MainActivity.java file turned blue. That means the file now has uncommitted changes (and it doesn’t match the file in the GitHub repository).

Uncommitted activity file

13. Now it’s up to you to make a commitment to keep track of your activities and progress. You can even push the changes after each and every amendment, or whenever you wish to. To do so, navigate to Git > Commit… or press (ctrl+K) to open the commit tab on the left side of the window.

commit….

14. Filling in the commit prompt is compulsory. But it is not mandatory to write the number of commits. You can name the current commit as you like or as understandable by the user. It is just to notify the user that this file has been modified or updated. After filling in the prompt, click the “Commit and Push” button for the next window.

Commit and push

15. Here, just look at the modified files that have to be changed in the repo and hit ‘push’ to change them on the website also.

Push

Here the confirmation popup message for the successful commit and push

And boom ! You now know how to keep track of your project while contributing to the GitHub platform directly from the Android Studio application. It will save you a lot of time and data, and comparatively, this method is easier to constantly update on GitHub rather than uploading manually there every once in a while.

I am Jai Surya, from SASTRA Deemed to be University.

Do clap if you find this useful.

--

--