How to switch android version in local repo?

You cannot solve this problem using repo forall.

Lets assume for certainty that your current Android tree is clean - no local changes or commits, i.e. repo status shows nothing.

To properly switch Android version, all you need to change is branch for your manifest repository. First determine the available branches with manifests for the different Android versions:

cd $ANDROID_ROOT
cd .repo/manifests
git branch -av   # see all available branches on origin

Select a version and

cd $ANDROID_ROOT
repo init -b <my_selected_android_version>

Such selective repo init with -b (without -u) will only update manifest branch and will not otherwise touch your tree.

Now, simply sync it:

repo sync -j8

and some time later, your Android tree will switch to another version.

Speed of this operation is mostly determined by how much default.xml manifest file differs between old and new Android versions - because if some git repository was added in new manifest, it will spend time cloning it. And if some repository was removed, if will actually blow it away.

But, by and large, this method is still much faster than initializing brand new Android tree from scratch.


if the branch you are in and the branch you will switch to has the same manifest.xml file, then you can use the following commands to do that.

repo forall -c git fetch aosp --tags 
repo forall -c git checkout -b john5.1.1_r14_api22 android-5.1.1_r14

also see details in http://johnliao52.github.io/2016/03/27/git-repo-skills.html