Getting Started With Git Version Control

Git (a distributed version control system) plays a key part in managing the source code used in Android. Repo itself (as discussed in the previous section) is itself a wrapper around a large number of git repositories of source code. The Linux kernel is tracked and maintained within a git repository of its own too.

For those unfamiliar with version control, the key advantage that a VCS (version control system) offers over plain, untracked sources, is the ability to access and maintain different revisions of the source code. Without a VCS, a user could copy their own code into a new folder regularly, when they made a new change. This is impractical for any large project though, as it results in a huge increase in the storage required for the source code, and with little actual benefit – it’s only possible to look at snapshots you created of the project, and each of these is an entire copy of your source code at that point in time.

Version control addresses this by tracking the actual changes made to the source code, and storing these changes incrementally. Git permits the developer to create multiple “branches” of their code, where they can diverge from the main source tree, and work on an experimental feature. Once the feature is completed, this branch can be merged into the main branch of the project, keeping the main branch clean and free from experimental (and often broken) code.

Within the Android Open Source Project (AOSP), Google uses branches within the code for each version released. There is a branch for Gingerbread, Ice-Cream Sandwich and Jellybean (more specifically the branches are actually for individual versions such as 4.1.1, 4.1.2 etc).
Git is also (per the description earlier) a distributed system, meaning that all users with a full copy of the source code have full access to the entire history of the repository, and all its past changes.

While git can be used standalone (ie. on one computer) to allow a developer to track changes to their own software, git is at its most useful when in a multi-user environment, where each user is making changes to the source code at all times. Everyone can work independently on their own changes, and share selectively the changes they wish to publish. A central git repository is used, to which users push their changes.

This is how Android’s sources are used. If you want to get involved in development, you will need to learn some git and repo basics, to be able to share your changes with other developers, and maybe even get them merged into the main code of your favourite ROM!

Want to Learn More?

The full Pro-Git book is available free online, and is definitely worth a read.

This post, by XDA Elite Recognized Developer Entropy512, is definitely worth a read if you are using git to work with kernels.

This guide, by XDA Forum Moderator eagleeyetom, is incredibly useful for anyone starting to work with Github for the first time.

This interactive tutorial is definitely worth trying out if you want to learn about git interactively. It will show you the basics within your browser, and is perhaps the fastest way to get some real experience of git.