Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android repo command and switching branches

Tags:

I feel I have a pretty good understanding of git, but when it comes to the repo command, I get lost. I've read about the repo command, but I'm still not sure how it ties everything together.

My biggest question is can I change my current branches from gingerbread to ICS and possibly back?

I see the command:

repo init -u https://android.googlesource.com/platform/manifest 

From my understanding, this will create a repo with the master branch. If I want to specify the branch, I can do:

repo init -u https://android.googlesource.com/platform/manifest -b android-4.0.1_r1 

The download is about 8GB, I believe, so I don't want to have to blow my repo away if they share code. is there a way to switch branches in repo?

like image 552
woodsdog Avatar asked Feb 01 '12 16:02

woodsdog


People also ask

How do I change branches in repository?

A quick way of switching branch on Git is to use the “git switch” command and specify the name of the branch you want to switch to. If the destination branch does not exist, you have to specify the “-c” option (for “create branch“), otherwise you will get an error message when switching to that branch.

Which command is used to switch to other branches?

The Git command git checkout is used to change between branches.

What is repo sync command?

If you run repo sync without arguments, it synchronizes the files for all projects. 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.

Does repo sync overwrite local changes?

repo sync does not overwrite local changes, so I don't think you're doing what you think you're doing. Can you give us a more detailed example of how you're using the command?


2 Answers

If you run repo init a second time with a different branch, you can simply repo sync and it will not download the entire source code again.

like image 75
gparent Avatar answered Sep 19 '22 13:09

gparent


The repo -b parameter specifies the branch of the .repo/manifests git repository that should be checked out. The default.xml file in this repository defines which branch each of the other git repositiories (projects) should be on.

It seems that repo is written in such a way that if you check out another manifest branch are repo sync again it will pull all the code again over the network.

You can run repo forall -c 'git checkout branch_name' which will checkout the specified branch for all projects that are declared in your current manifest but if there are projects added/removed between gingerbread and ics (which there are), then you won't get the code for these projects.

Running git checkout branchname in the .repo/manifests repository then running repo sync may enable you to save some network overhead.

Otherwise, due to the limitations of repo, the only real way to do it is to maintain two working copies of the aosp or be prepared to re-sync.

like image 30
aultimus Avatar answered Sep 17 '22 13:09

aultimus