To work with the Android code, you will need to use both Git and Repo.
- Git
is an open-source version-control system designed to handle very large projects that are distributed over multiple repositories. In the context of Android, we use Git for local operations such as local branching, commits, diffs, and edits.
- Repo
is a tool that we built on top of Git. Repo helps us manage the many Git repositories, does the uploads to our revision control system
, and automates parts of the Android development workflow. Repo is not meant to replace Git, only to make it easier to work with Git in the context of Android. The repocommand is an executable Python script that you can put anywhere in your path.
In working with the Android source files, you will use Repo for across-network operations. For example, with a single Repo command you can download files from multiple repositories into your local working directory.
About Git
Why Git?
One of the challenges in setting up the Android project was figuring out how to best support the outside community--from the hobbiest community to large OEMs building mass-market consumer devices. We wanted components to be replaceable, and we wanted interesting components to be able to grow a life of their own outside of Android. We first chose a distributed revision control system, then further narrowed it down to Git.Already a Git user?
In most situations, you can use Git instead of Repo, or mix Repo and Git commands to form complex commands. Using Repo for basic across-network operations will make your work much simpler, however.
Task reference
The task list below shows a summary of how to do common Repo and Git tasks.
For complete quick-start information and examples, see Get source
.
Installing Repo
$ curl http://android.git.kernel.org/repo > ~/bin/repo $ chmod a+x ~/bin/repo
$ mkdir working-directory-name
$ cd working-directory-name
$ repo init -u git://android.git.kernel.org/platform/manifest.git
Synchronizing your client
To synchronize the files for all available projects:$ repo sync
To synchronize the files for selected projects:
$ repo sync project1 project2 ...
Why use topic branches?
Start a topic branch in your local work environment whenever you begin a change, for example when you begin work on a bug or new feature.A topic branch is not a copy of the original files; it is a pointer to a particular commit. This makes creating local branches and switching among them a light-weight operation. By using branches, you canisolateone aspect of your work from the others. For an interesting article about using topic branches, see Separating topic branches .
Creating topic branches
To start a topic branch using Repo:$ repo start branchname
To verify that your new branch was created:
$ repo status
Using topic branches
To assign the branch to a particular project:$ repo start branch name project
To switch back and forth among branches that you have created in your local work environment:
$ git checkout branchname
To see a list of existing branches:
$ git branch
or...
$ repo branches
The name of the current branch will be preceded by an asterisk.
Note:
A bug might be causing repo sync to reset the local topic branch. If git branch shows * (no branch) after you run repo sync, then run git checkoutagain.
A bug might be causing repo sync to reset the local topic branch. If git branch shows * (no branch) after you run repo sync, then run git checkoutagain.
Viewing client status
To list the state of your files:$ repo status
To see uncommitted edits:
$ repo diff
Therepo diffcommand shows every local edit that you have made that would not go into the commit, if you were to commit right now.
To see every edit that would go into the commit if you were to commit right now, you need a Git command, git diff. Before running it, be sure you are down in the project directory:
$ cd ~/workingdirectory /project
$ git diff --cached
Recovering sync conflicts
If a repo sync shows sync conflicts:- View the files that are unmerged (status code = U).
- Edit the conflict regions as necessary.
- Change into the relevant project directory, run git add and git commit for the files in question, and then "rebase" the changes. For example:
$ cd bionic
$ git add bionic/*
$ git commit
$ git rebase --continue - When the rebase is complete start the entire sync again:
$ repo syncbionic proj2 proj3 ... projN
Cleaning up your client files
To update your local working directory after changes are merged in Gerrit:$repo sync
To safely remove stale topic branches:
$ repo prune
Deleting a client
Deleting a client will permanently delete any changes you have not yet uploaded for review.Becauseall state information is stored in your client, you only need to delete the directory from your filesystem:$ cd ~
$ rm -rf working-directory-name
Scripting common tasks
You can use Repo to run the same program across all projects:$ repo forall[proj1 proj2 ... projN ]-c 'echo $REPO_PROJECT $@ '[arg1 arg2 ... argN ]
The -c argument is evaluated through /bin/sh and any arguments after it are passed through as shell positional parameters.
Repo command reference
Repo usage takes the following form:repo command options
Optional elements are shown in brackets[ ]. Once Repo is installed, you can get information about any command by running
repo help command
init
repo init -u url [options ]Installs Repo in the current directory. This creates a .repo/ directory that contains Git repositories for the Repo source code and the standard Android manifest files. The .repo/ directory also containsmanifest.xml, which is a symlink to the selected manifest in the .repo/manifests/ directory.
The -u argument specifies a URL from which to retrieve a manifest repository. For example:
$ repo init -u git://android.git.kernel.org/platform/manifest.git
To select a manifest file within the repository, use the -m option. (If no manifest name is selected, the default is default.xml.)For example:
$ repo init -u git://android.git.kernel.org/platform/manifest.git-m dalkvik-plus.xml
To specify a revision, that is, a particular manifest-branch, use the -b option. For example:
$ repo init -u git://android.git.kernel.org/platform/manifest.git-b release-1.0
To see other repo init options, run
$ repo help init
Note: For all remaining Repo commands, the current working directory must either be the parent directory of .repo/ or a subdirectory of the parent directory.
The -u argument specifies a URL from which to retrieve a manifest repository. For example:
$ repo init -u git://android.git.kernel.org/platform/manifest.git
To select a manifest file within the repository, use the -m option. (If no manifest name is selected, the default is default.xml.)For example:
$ repo init -u git://android.git.kernel.org/platform/manifest.git-m dalkvik-plus.xml
To specify a revision, that is, a particular manifest-branch, use the -b option. For example:
$ repo init -u git://android.git.kernel.org/platform/manifest.git-b release-1.0
To see other repo init options, run
$ repo help init
Note: For all remaining Repo commands, the current working directory must either be the parent directory of .repo/ or a subdirectory of the parent directory.
sync
repo sync [project-list ]Downloads new changes and updates the working files in your local environment. After a successful repo sync, the code in specified projects will be up to date with the code in the remote repository.
You can specify project-list as a list of names or a list of paths to local source directories for the projects:
repo sync [proj1 proj2 ... projN ]
If you run repo sync without any arguments, it will synchronize the files for all the projects.
You can specify project-list as a list of names or a list of paths to local source directories for the projects:
repo sync [proj1 proj2 ... projN ]
If you run repo sync without any arguments, it will synchronize the files for all the projects.
How Repo synchronization works
When you run repo sync, this is what happens:
- If the project has never been synchronized, then repo sync is equivalent to git clone. All branches in the remote repository are copied to the local project directory.
- If the project has already been synchronized once, then repo sync is equivalent to:
git remote update
git rebase origin/branch
where branch is the currently checked-out branch in the local project directory. If the local branch is not tracking a branch in the remote repository, then no synchronization will occur for the project.
If the git rebase operation results in merge conflicts, you will need to use the normal Git commands (for example, git rebase --continue) to resolve the conflicts.
The repo sync command also updates the private repositories in the .repo/ directory.
upload
repo upload [project-list ]For the specified projects, Repo compares the local branches to the remote branches updated during the last repo sync. Repo will prompt you to select one or more of the branches that have not yet been uploaded for review.
After you select one or more branches, all commits on the selected branches are transmitted to Gerrit over an SSH connection.You will need to configure an SSH key to enable upload authorization.Visit SSH Keys within the user settings panel to register your public keys with Gerrit.To enable password-less uploads, consider using ssh-agent on your client system.
When Gerrit receives the object data over its SSH server, it will turn each commit into a change so that reviewers can comment on each commit individually.
To combine several "checkpoint" commits together into a single commit, use git rebase -i before you run repo upload.
You can specify project-list as a list of names or a list of paths to local source directories for the projects:
repo upload [proj1 proj2 ... projN ]
If you run repo upload without any arguments, it will search all the projects for changes to upload.
To make edits to changes after they have been uploaded, you should use a tool likegit rebase -ior git commit --amend to update your local commits.
After your edits are complete:
After you select one or more branches, all commits on the selected branches are transmitted to Gerrit over an SSH connection.You will need to configure an SSH key to enable upload authorization.Visit SSH Keys within the user settings panel to register your public keys with Gerrit.To enable password-less uploads, consider using ssh-agent on your client system.
When Gerrit receives the object data over its SSH server, it will turn each commit into a change so that reviewers can comment on each commit individually.
To combine several "checkpoint" commits together into a single commit, use git rebase -i before you run repo upload.
You can specify project-list as a list of names or a list of paths to local source directories for the projects:
repo upload [proj1 proj2 ... projN ]
If you run repo upload without any arguments, it will search all the projects for changes to upload.
To make edits to changes after they have been uploaded, you should use a tool likegit rebase -ior git commit --amend to update your local commits.
After your edits are complete:
- Make sure the updated branch is the currently checked out branch.
- Use repo upload --replace proj1 to open the change matching editor.
- For each commit in the series, enter the Gerrit change Id inside the brackets:
# Replacing from branch foo
[ 3021 ] 35f2596c Refactor part of GetUploadableBranches to lookup one specific...
[ 2829 ] ec18b4ba Update proto client to support patch set replacments
[ 3022 ] c99883fe Teach 'repo upload --replace' how to add replacement patch se...
# Insert change numbers in the brackets to add a new patch set.
# To create a new change record, leave the brackets empty.
After the upload is complete the changes will have an additional Patch Set (e.g. Patch Set 2, Patch Set 3, ...).
[ 3021 ] 35f2596c Refactor part of GetUploadableBranches to lookup one specific...
[ 2829 ] ec18b4ba Update proto client to support patch set replacments
[ 3022 ] c99883fe Teach 'repo upload --replace' how to add replacement patch se...
# Insert change numbers in the brackets to add a new patch set.
# To create a new change record, leave the brackets empty.
After the upload is complete the changes will have an additional Patch Set (e.g. Patch Set 2, Patch Set 3, ...).
diff
repo diff [project-list ]Shows changes between commit and working tree.
You can specify project-list as a list of names or a list of paths to local source directories for the projects:
repo diff [proj1 proj2 ... projN ]
Options:
-h, --helpmeans show this help message and exit.
You can specify project-list as a list of names or a list of paths to local source directories for the projects:
repo diff [proj1 proj2 ... projN ]
Options:
-h, --helpmeans show this help message and exit.
download
repo download target
change
Downloads the specified change into the specified local directory. (Added to Repo as of version 1.0.4.)
For example, to download change 1241 into your platform/frameworks/base directory:
$ repo download platform/frameworks/base 1241
A"repo sync"should effectively remove any commits retrieved via "repo download".Or, you can check out the remote branch; e.g., "git checkout m/master".
Note: As of Jan. 26, 2009, there is a mirroring lag of approximately 5 minutes between when a change is visible on the web in Gerrit and when repo download will be able to find it, because changes are actually downloaded off the git://android.git.kernel.org/ mirror farm. There will always be a slight mirroring lag as Gerrit pushes newly uploaded changes out to the mirror farm.
For example, to download change 1241 into your platform/frameworks/base directory:
$ repo download platform/frameworks/base 1241
A"repo sync"should effectively remove any commits retrieved via "repo download".Or, you can check out the remote branch; e.g., "git checkout m/master".
Note: As of Jan. 26, 2009, there is a mirroring lag of approximately 5 minutes between when a change is visible on the web in Gerrit and when repo download will be able to find it, because changes are actually downloaded off the git://android.git.kernel.org/ mirror farm. There will always be a slight mirroring lag as Gerrit pushes newly uploaded changes out to the mirror farm.
forall
repo forall [project-list ] -c command [arg. ..]Runs a shell command in each project.
You can specify project-list as a list of names or a list of paths to local source directories for the projects
You can specify project-list as a list of names or a list of paths to local source directories for the projects
help
repo help [command ]Displays detailed help about a command.
prune
repo prune [project-list
]Prunes (deletes) topics that are already merged.
You can specify project-list as a list of names or a list of paths to local source directories for the projects:
repo prune [proj1 proj2 ... projN ]
You can specify project-list as a list of names or a list of paths to local source directories for the projects:
repo prune [proj1 proj2 ... projN ]
start
repo start newbranchname [project-list ]Starts a new branch for development.
The newbranchname argument should provide a short description of the change you are trying to make to the projects.If you don't know, consider using the name default.
The project-list specifies which projects will participate in this topic branch. You can specify project-list as a list of names or a list of paths to local working directories for the projects:
repo start default [proj1 proj2 ... projN ]
"." is a useful shorthand for the project in the current working directory.
The newbranchname argument should provide a short description of the change you are trying to make to the projects.If you don't know, consider using the name default.
The project-list specifies which projects will participate in this topic branch. You can specify project-list as a list of names or a list of paths to local working directories for the projects:
repo start default [proj1 proj2 ... projN ]
"." is a useful shorthand for the project in the current working directory.
status
repo status [project-list ]Shows the status of the current working directory. You can specify project-list as a list of names or a list of paths to local source directories for the projects:
repo status [proj1 proj2 ... projN ]
To see the status for only the current branch, run
repo status .
The status information will be listed by project. For each file in the project, a two-letter code is used:
repo status [proj1 proj2 ... projN ]
To see the status for only the current branch, run
repo status .
The status information will be listed by project. For each file in the project, a two-letter code is used:
- In the left-most column, an uppercase letter indicates what is happening in the index (the staged files) when compared to the last committed state.
- In the next column, a lowercase letter indicates what is happening in the working directory when compared to the index (what is staged).
Character | Meaning |
A | The file is added (brand new). Can only appear in the first column. |
M or m |
The file already exists but has been modified in some way. |
D or d |
The file has been deleted. |
R | The file has been renamed. Can only appear in the first column. The new name is also shown on the line. |
C | The file has been copied from another file. Can only appear in the first column. The source is also shown. |
T | Only the file's mode (executable or not) has been changed. Can only appear in the first column. |
U | The file has merge conflicts and is still unmerged. Can only appear in the first column. |
- | The file state is unmodified. A hyphen in both
columns means this is a new file, unknown to Git. After you run git add on this file, repo status will show A-, indicating the file has been added. |
For example, if you edit the file main.py within the appeng project without staging the changes, then repo status might show
project appeng/
-mmain.py
If you go on to stage the changes to main.py by running git add, then repo status might show
project appeng/
M- main.py
If you then make further edits to the already-staged main.py and make edits to another file within the project, app.yaml, then repo status might show
project appeng/
-mapp.yaml
Mm main.py
Git and Repo cheatsheet
Click on the cheatsheet to open it in a new window for easier printing.Terminology
Staged changesChanges marked by git add for inclusion in the next commit's snapshot.
Commit
At intervals, you use git commit to save a snapshot of the staged files and a log message that describes the change.
Manifest
A manifest file that contains a list of repositories and a mapping of where the files from these repositories will be located within your working directory. When you synchronize your files, the files contained in the repositories that are listed in the manifest will be pulled into your working directory.