Using Git in Android Studio.

By | December 15, 2016

If you set git repository to an installed GitLab and empty project is set up, let’s use this git repository now.

Using Git in Android Studio.


First, if you want to use git in Android Studio, you need to have git for Windows installed by default.

Windows Git: https://git-scm.com/

Installing Windows Git is not that hard, so I did not add any additional comments.
For reference, 2.7.2 is used as of March 31, 2016.

Once you’ve installed git, let’s set up git stub on Android Stduio.

Check out using git in Android Studio and set the git.exe executable


1. Android studio> VCS> Enable Version Control Integration
Select the above menu and select the version control system to use as the Git.

2. Go to Android Studio> File> Settings …> Version Control> Git
Select the above item and enter the location of git.exe, the executable file for Git for Windows.

Set the path of Git and click the Test button to see if it runs normally.

All the default settings are now complete.

To reflect Git, proceed as follows.

Git add: Add Stage
Git commit, push: save to local repository and remote repository

Git add in Android Studio


Let’s try git add so we can put it in the git repository

Right-click on the desired folder or file and select Go> Add.

The file color is red before Git add, but it changes to green after Git add.

Git commit, push in Android Studio


This time you need git commit and push to put the code in GitLab.

Git commit: local reflected in repository
Git push: remote reflected in repository

It can be reflected in remote storage only after the above two steps.
(Note that Android Studio also allows you to save one button at a time.)

-. Git commit

Simply type in the Commit Message for the purpose of the commit and press the commit button.


In order to upload to the remote repository, you have to commit and push. If you select a separate push menu after committing, you will have a Commit and Push button to commit and push at once.

-. Git push

When Commit and Push is done, it goes directly to the Push setting screen.
This push process is a push into the remote repository.

The first time you push it, you will not have any information about the remote repository. Let’s select “Define remote”.

When you select it, a popup pops up for you to enter the remote repository information.

In the case of outgoing, we used the address using http instead of ssh.

http://OOO.OOO.OOO.OOO/toolbox2015/TEST_PROJECT.git

When the setting is completed as above, press Push.
If you wait a bit, you’ll be done. Go to the GitLab web page and see if it’s been pushed normally.

You can see that there is a single commit named initial commit as shown below.


Now I have confirmed what to upload, but what do I do when I download it?

Git pull in Android Studio
Now let’s get the code uploaded to GitLab.

There are two ways to get the code.

-. How to set up a project and receive it in its entirety
-. How to get only some edits

Let’s check one by one.

-. How to set up a project and receive it in its entirety
Strictly speaking, this part is not an git pull, but an entire copy through git clone.

On the first Android Studio screen, select “Check out project from Version Control” and enter the Git repository information you want to import.

This is roughly equivalent to the Git Repository URL.

http://OOO.OOO.OOO.OOO/toolbox2015/TEST_PROJECT.git

And if you do not know, let’s press the Test button. If you successfully enter the credential window and enter it correctly, the success popup will occur as shown below.

Now that you have verified that you have access to the remote repository, press the Clone button.
Once the project has been cloned, you can work on it from now on, and if it does, you can do it with git commit and push.

-. How to get only some edits

It will be clean if you receive the whole thing, but you can not always receive it whole.

When this happens, let’s just pull the part that you want to receive.

Select the desired part of the project and click the right mouse button to open the popup menu.

Go to> Repository> Pull

After selecting it, a popup will appear as shown below. Press the pull button below to pull it.


In this way, Android Studio allows you to use Git through the UI.

Let’s try Git through our own Git Repository or Git repository service provider.
If Git can manage the code systematically, you can have a better development environment including existing history management.

One thought on “Using Git in Android Studio.

Leave a Reply

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