how do I switch branches by repo

41690 views
Skip to first unread message

allstars

unread,
Dec 21, 2010, 5:15:42 AM12/21/10
to Android Building
hi
recently I do 'repo sync' to get gingerbread codebase

and now I try to build the gingerbread-release branch
so I do
repo forall -c git checkout remotes/korg/gingerbread-release

but when I try to build it

I found errors like 'need to add LOCAL_MODULE_TAGS := optional"
in frameworks/policies/base/phone/Android.mk

and I realized that in frameworks/policies/base/ it doesnt have the
branch remotes/korg/gingerbread-release
and this problem exists in many projects so I dont want to fix the
problem one by one

so how do I switch branches easily in mydroid?


thanks

Jean-Baptiste Queru

unread,
Dec 21, 2010, 8:39:06 AM12/21/10
to android-...@googlegroups.com
repo init -b android-2.3_r1 ; repo sync

In order to be able to checkout between branches the way you did:

-you need to know ahead of time that the list of projects is the same
in your source and destination branches (which is very rarely the
case)

-you need to know ahead of time that the branch name is the same in
all projects (which is also quite rare)

-you need to switch to a branch that makes sense (beware,
"gingerbread-release" isn't guaranteed to make any sense)

-you need to know that you won't be able to upload and that your local
state will be wiped the next time you sync

JBQ

> --
> You received this message because you are subscribed to the "Android Building" mailing list.
> To post to this group, send email to android-...@googlegroups.com
> To unsubscribe from this group, send email to
> android-buildi...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-building?hl=en
>

--
Jean-Baptiste M. "JBQ" Queru
Software Engineer, Android Open-Source Project, Google.

Questions sent directly to me that have no reason for being private
will likely get ignored or forwarded to a public forum with no further
warning.

dyndragon

unread,
Dec 21, 2010, 8:41:00 AM12/21/10
to android-...@googlegroups.com
I'm sort of new to this (so if I'm wrong, someone please correct me--just trying to help), but I'm pretty sure you just need to:

repo init -u git://___________ -b <branch>

where <branch> is 'froyo', or 'gingerbread' or whatever. This is how i'm switching between branches when building.

Shachar Shemesh

unread,
Dec 21, 2010, 9:00:07 AM12/21/10
to android-...@googlegroups.com, allstars

Here's how I do it. It allows switching between dissimilar branches, and
allows uploading the results.

Lets say you are on froyo, and want to check out gingerbread-release, as
you said:

repo init -b gingerbread-release

(answer the silly questions)

repo sync (not needed if your local copy is up to date, but is needed
the first time, even if you already "repo sync" before the "repo init")

repo start gingerbread-release --all

That last command creates a branch for you to work on. Any time in the
future you check out that branch, you will get something based on the
correct version.

repo checkout gingerbread-release

You're good to go. If you want to upload anything to gerrit, you will
need to use "master" for your "repo init". Any time anything major
changes (such as now), you will also need to repeat the "repo start
master --all" command. You might need to erase the old master branch
before you do. repo prune might be your friends here.

If you made a change in a non-master branch, and you want to upload it,
just use git in the project itself to transfer your changes between the
branch and the master branch, and then use repo to upload them as usual.

Shachar

--
Shachar Shemesh
Lingnu Open Source Consulting Ltd.
http://www.lingnu.com

allstars

unread,
Dec 21, 2010, 10:21:33 PM12/21/10
to Android Building
guys thanks for your responding

but I still have one more question

so I have to do repo init and repo sync again
to pull the remote branches?

but this is the 'svn' style, right?
coz when git pull , it would pull all branches into my local pc

what I think is
I simply can do
repo forall -c git checkout android-2.3r1

so I dont have to do init and sync again

Is that correct?

(of course If I should use my local branches I should take Shachar's
opinion
to do repo start)

Jean-Baptiste Queru

unread,
Dec 21, 2010, 10:54:54 PM12/21/10
to android-...@googlegroups.com
You can re-run repo init on the same client, such that repo sync will
only re-download the new data.

You can't just checkout in all projects, because (like I explained above):
-the list of projects changes from one branch to another, so the
notion of "all projects" can't be used to go across branches
-there's not a 1:1 mapping between names of manifests and names of
branches in individual projects.

As an extra trick, if you already have a client tracking one branch
and want a client tracking another branch:

create a new empty directory
run repo init in it (with the -u parameter)
copy the .repo/projects directory from your existing client into the new one.
repo sync

That'll only download the projects you don't already have.

JBQ

Shachar Shemesh

unread,
Dec 22, 2010, 2:01:20 AM12/22/10
to android-...@googlegroups.com, Jean-Baptiste Queru
On 22/12/10 05:54, Jean-Baptiste Queru wrote:
> create a new empty directory
> run repo init in it (with the -u parameter)
> copy the .repo/projects directory from your existing client into the new one.
> repo sync
>
> That'll only download the projects you don't already have.
>
Is there any way to do this without taking up an additional 3.8GB of
space on the hard disk? In particular, can I, instead of copying
.repo/projects, just symlink it?

I know Google is paying for big fat machines to its developers, but some
of us consultants work on a budget and/or need to take our work machine
with us on a shoulder strap (actually, mine's a backpack, but the
argument still stands).

Jean-Baptiste Queru

unread,
Dec 22, 2010, 8:48:22 AM12/22/10
to android-...@googlegroups.com
You can also switch in place: just run "repo init -b
<new_manifest_branch>; repo sync" in your existing client.

If you're planning to upload those changes to a server, you'll need to
repo start new branches after the switch if you want then to be
uploaded to the right server branch.

JBQ

--

roylee17

unread,
Jan 9, 2011, 6:06:15 AM1/9/11
to Android Building
I've previously submitted a patch for this kind of purpose --
switching
between branches that are composed of different set of projects.

https://review.source.android.com/#change,18930

The idea is simple enough as you guys may have already been doing so
for some time *manually*.
Creating the .repo/projects as symlink to an existing pool of projects
during 'repo init'.


Let me quote the commit message to save some time of typing :)
------------
init and sync: add --shared=DIR option to share bare repositories

The --shared=DIR option allows multiple android projects to share
the same set of a local repository pool, which contains the super
set of all the individual projects needed by each android project.
It links the .repo/projects to the specified one, instead of
creating its own.

If we have three android projects for different product lines.
And they are composed with different set of projects.

P1: A B C D
P2: A B C E
P3: A B D E

The following command sequence will save a lot of traffics:

$ cd wrk/p1
$ git init --shared=<somewhere/pool> -u <server> -b <branch_for_p1>
$ repo sync

$ cd wrk/p2
$ git init --shared=<somewhere/pool> -u <server> -b <branch_for_p2>
$ repo sync

$ cd wrk/p3
$ git init --shared=<somewhere/pool> -u <server> -b <branch_for_p3>
$ repo sync

during developemnt, the 'repo sync' on whichever project will also
benefit to the others.

Regards,
Roy

Jean-Baptiste Queru

unread,
Feb 19, 2013, 11:25:19 AM2/19/13
to android-...@googlegroups.com
Use "repo init -b <branch> ; repo sync"

JBQ

On Sun, Feb 17, 2013 at 11:27 PM, jean <zhangj...@gmail.com> wrote:
> I have same require too.
>
> And I use this way to get the new branch
>
> 1. cd .repo/manifests/
>
> 2. git branch -a #remember the branch name you want to checkout
>
> 3. git checkout --trace orgin/xxxx/xxxx
>
> 4. cd ../..
>
> 5. repo sync
>
>
>
> 在 2010年12月21日星期二UTC+8下午6时15分42秒,allstars写道:
> --
> --
> You received this message because you are subscribed to the "Android
> Building" mailing list.
> To post to this group, send email to android-...@googlegroups.com
> To unsubscribe from this group, send email to
> android-buildi...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-building?hl=en
>
> ---
> You received this message because you are subscribed to the Google Groups
> "Android Building" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to android-buildi...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>



--
Jean-Baptiste M. "JBQ" Queru
Technical Lead, Android Open Source Project, Google.
Reply all
Reply to author
Forward
0 new messages