Post

Managing Android Repositories Efficiently with Repo Tool

Managing Android Repositories Efficiently with Repo Tool

Repo is a tool built on top of Git that simplifies working with multiple repositories. It streamlines uploads to revision control systems, automates parts of the development workflow, and manages Git repositories efficiently.

Note: Repo does not replace Git. Instead, it enhances Git usage in large, multi-repo projects like Android.

The repo command is a Python script that you can place anywhere in your system’s PATH.


πŸ› οΈ Installation Guide

Repo installation consists of two parts:

  1. A launcher script.
  2. The full Repo tool, which is fetched during initialization.

πŸ” Method 1: Install via APT (Debian/Ubuntu)

1
2
sudo apt-get update
sudo apt-get install repo

This may not always provide the latest version.

πŸ”§ Method 2: Manual Installation

If apt doesn’t work or the version is outdated, install manually:

1
2
mkdir ~/bin
export PATH=~/bin:$PATH

πŸ“₯ Download and Setup the Repo Launcher

1
2
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo

πŸ” (Optional) Verify the Signature

1
2
gpg --recv-key 8BB9AD793E8E6153AF0F9A4416530D5E920F5C65
curl https://storage.googleapis.com/git-repo-downloads/repo.asc | gpg --verify - ~/bin/repo

⚑ One-liner Installation

1
2
3
4
export REPO=$(mktemp /tmp/repo.XXXXXXXXX)
curl -o ${REPO} https://storage.googleapis.com/git-repo-downloads/repo
gpg --recv-key 8BB9AD793E8E6153AF0F9A4416530D5E920F5C65
curl -s https://storage.googleapis.com/git-repo-downloads/repo.asc | gpg --verify - ${REPO} && install -m 755 ${REPO} ~/bin/repo

🏁 Initializing a Repo Client

Create a working directory:

1
2
mkdir WORKING_DIRECTORY
cd WORKING_DIRECTORY

🧾 Configure Git Identity

1
2
git config --global user.name "Your Name"
git config --global user.email you@example.com

Use a Google-linked email address for Gerrit code review.

🌐 Initialize Repo

1
repo init -u https://android.googlesource.com/platform/manifest

Or specify a branch:

1
repo init -u https://android.googlesource.com/platform/manifest -b master

πŸ“₯ Downloading Android Source Code

Run:

1
repo sync

⚑ Speed Up Sync

1
repo sync -c -j8

-c Sync current branch only
-j8 Use 8 threads
-q Add this flag for quieter output

πŸ”½ Minimal Sync (Shallow Clone)

Use this to reduce bandwidth and sync time:

1
2
repo init --depth=1 -u https://android.googlesource.com/platform/manifest -b master
repo sync -f --force-sync --no-clone-bundle --no-tags -j$(nproc --all)
1
2
repo init -u https://android.googlesource.com/platform/manifest -b master \
  --partial-clone --clone-filter=blob:limit=10M

Ideal for low-latency networks β€” downloads objects only when needed.

πŸ“‘ Using a Local Mirror (Bandwidth Saver)

Create a local mirror to avoid repeated network downloads.

πŸͺž Step 1: Create the Mirror

1
2
3
4
mkdir -p /usr/local/aosp/mirror
cd /usr/local/aosp/mirror
repo init -u https://android.googlesource.com/mirror/manifest --mirror
repo sync

πŸ’» Step 2: Create Clients from Mirror

1
2
3
4
mkdir -p /usr/local/aosp/master
cd /usr/local/aosp/master
repo init -u /usr/local/aosp/mirror/platform/manifest.git
repo sync

πŸ”„ Step 3: Sync Mirror & Client

1
2
3
4
cd /usr/local/aosp/mirror
repo sync
cd /usr/local/aosp/master
repo sync

Mirror can be shared via LAN (NFS, SSH, Git) or removable drives.

🧹 Resetting the Repo Workspace

πŸ”„ Discard Local Changes

1
repo forall -c "git reset --hard"

🧼 Full Clean (Untracked Files Too)

1
repo forall -c 'git reset --hard ; git clean -fdx'

πŸ—‘οΈ Hard Reset (Preserving .repo)

1
rm -rf * && repo sync -l

πŸ“š References & Resources

πŸ“–Android Source Developer Guide – Google
πŸ’¬StackOverflow: Discard Changes Using Repo

This post is licensed under CC BY 4.0 by the author.