Introduction: Using Google's Repo Command in Your Own Projects

I maintain a project that has numerous git repositories and I was interested in setting it up to use the repo tool. If you are unfamiliar with repo, you can read up on it here.

Essentially repo wraps up numerous git repositories into one location, kind of like git submodules but without the pain. The basics behind how it works are as follows:

1. repo init -u "url"
2. repo sync

The repo init is important, the url you specify points to a git repository. In that git repository is a default.xml file that is used to control the repo sync. That xml file is used to tell repo where your git repositories are and how to save them on the computer.

We will see how this works in depth a bit more later.

I am going to assume that you have git repositories already that you have access to them as well. I am also assuming your on Ubuntu 10.04, but any Linux should work, but I use Ubuntu 10.04.


Step 1: Creating a Default Manifest

First things first, you need another git repository. Go ahead and create a repo and clone it to your machine. After that is done, create a default.xml file. You can find a working example for the miniat.bitbucket.org attached.

The first thing you need to configure in that file is the <remote> tag. This tag specifies to repo where to go to get your repositories. You then associate repos with remotes. You can have multiple remotes, so feel free to scatter your repos around the web.

<remote  name="give it a unique name here"
           fetch="url to repo with out server path" />

After that, you should specify what the default behavior should be, you can specify revisions you want to check out, etc. The revisions must be found in the .git/ folder. I usually use refs/heads/master, as I want the default to track the master branch of all my projects. 

  <default revision="refs/heads/master"
           remote="bitbucket"
           sync-j="4" />

Now we need to add repositories with the <project> tag. Note that path is not mandatory...

<project name="git repo path on server" remote="remote to associate with repository" path="what to name the created directory"/>

Example:
<project name="miniat/0x1-miniat" remote="bitbucket" path="vm"/>

You can have as many projects as you like.

Don't forget to git add, git commit -m "message here" git push your repo back to the server. 

This is all their is too it, don't forget you need the whole thing in proper format, use the file provided as a template. Their are other options I didn't specify, but you can clone Android Open Source Project and look at their manifests to get an idea of more options.


Step 2: Get Repo

Now that you have a config (default.xml) file and it is pushed back to the server we need to get the repo tool.

Do the following commands:

$ mkdir ~/bin
$ PATH=~/bin:$PATH
Download the Repo script and ensure it is executable:

$ curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo
$ chmod a+x ~/bin/repo

Step 3: Using Repo

Now that we have repo, you can clone all your projects in one easy command.

repo init -u <url>

where url is the checkout url used for git cloning your repository with the default.xml file.

On my project it is:
$ repo init -u ssh://git@bitbucket.org/miniat/default

Then from there just run:
$ repo sync