Android Studio Built-in VCS Integration

Reading This Manual

Copying all content from this file and pasting it at https://jbt.github.io/markdown-editor/ will not display images and gif animations since they are stored locally within the repository. It is strongly recommended to read this document inside Atom text editor using Ctrl + Shift + M to display the rendered preview.

Introduction

Git has become an indispensable tool for every serious and successful software project. But there are times when developers wish they have some visual representation of what they are working on instead of ‘bashing out’ everything blindly using a black console screen. In fact, many programs exist solely for that purpose but as separate software running separate windows and requiring more resources from your machine. Luckily, smart IDEs like Android Studio have a built-in VCS integration that supports almost every functionality provided by Git within the same window. This manual aims to show you how to integrate Git in your Android Studio, show you around some of its features and simulate doing basic Git operations using a basic workflow scenario.

How to Integrate VCS in Android Studio

Option 1

1. Clone the repository using the command $ git clone <YOUR_GIT_REPO>

git clone

2. Open Android Studio, click on “Open an existing Android Studio project” option and then select the project folder and click “OK”
3. Once Android Studio has finished loading, The IDE will show a popup saying that it has detected an unregistered VCS root. Click “Add root”. Now Android Studio Version Control tab is available for you.

How to integrate VCS in Android Studio: Option 1

Option 2

1. Open Android Studio and select “Checkout project from version control” option and then select “Git” from the dropdown menu
2. Paste the Git Repository URL and then click on Clone.
3. Once cloned, Android Studio will ask you whether you want to open the project you just cloned or not. Click Yes.
4. Version Control tab will automatically be there as soon as loading the project finishes.

How to integrate VCS in Android Studio: Option 2

Version Control Tab

The Version Control tab contains two main sections: 1. Local Change: This section keeps track of locally made file changes. File names are shown in different colors. See File Color Code in Android Studio VCS section to learn more.

VCS local change

  1. Log: This section displays local and remote branches, commits, commit messages, authors, timestamp, etc. Clicking on one commit displays the different changes introduced in the right pane.

VCS log

File Color Code in Android Studio VCS

To make file changes like addition, modification, deletion etc. stand out, Android Studio uses a smart color code: – Red: Newly added file to the Local repository that is neither added to Git nor is included in .gitignore file. – Green: Newly added file to the Local repository that has been added to Git. – Blue: Modified file. – Grey: Deleted file in a commit. – Black: Anything that is not the above.

Revert Option

The developer can sometimes change a file so much that going back to the original repository version becomes impossible using Ctrl + Z shortcut. For that, Android Studio provides you with the simple “Revert” option to sort this out. Simply use Ctrl + Alt + Z shortcut.

VCS revert

Basic Workflow Scenario

Commit Changes to a New Branch

  1. First, you should update the project to make sure that you are branching out from the latest revision.
  2. Create a new local branch from the latest revision of master.
  3. Add unversioned files to Git (or to .gitignore if you don’t want to include them in your commit).
  4. Use the shortcut Ctrl + K to open “Commit Changes…” Window. Write your commit message, then click on “Commit and Push”
  5. You could include the author’s name if you want, but Git does that automatically anyways.
  6. A “Push…” window will pop up. Just click on push. Git will create a remote branch with the same name as the local one and push the changes made on the local branch to its remote counterpart.

See the animation below:

Commit changes to a new branch

Merge into master

To merge our branch into master, we will need to follow these steps: 1. Checkout the master branch. 2. Right click on the latest revision of our branch and select “Merge” option from the “Branch branch” menu.

See the animation below:

Merge into master

Push Changes

Now that you merged into master, it remains to make that change happen on the remote repository as well. in other words, the merge we did in the previous step was only done locally and we still have to push the changes to remote master branch. To do that, simply use Ctrl + Shift + K to open “Push…” window and then click on “Push” button from there.

See the animation below:

Push changes

Conclusion

You are now set to work with Git using the built-in Android Studio VCS Integration functionality. Of course, Git operations are not just the ones covered in this manual. However, if you mastered the above operations, you will be able to do all other operations, like diff for example, just as easy.

Author: Iskander Gaba

Leave a Comment