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:
- A launcher script.
- 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)
π§ Partial Clones (Git 2.19+ Recommended)
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