I have a question about switching branches using repo. I know that I can checkout a branch like this:
$ repo init ... -b foo
$ repo sync
My understanding is that this will checkout the foo branch of the manifest repository, and then check out the git projects as described in the manifest.
I also understand that I can switch branches like this:
$ repo init ... -b bar
$ repo sync -d
My question is, can I switch branches without doing repo init & repo sync each time, and what are the implications of doing so?
Let me illustrate with an example:
$ repo init ... -b foo
$ repo sync -d
$ repo start foo-mytopic proj1 proj2
... make some commits ...
$ repo upload -t
$ repo init ... -b bar
$ repo sync -d
$ repo start bar-topic proj1 proj3
$ repo upload -t
$ cd proj1
$ git checkout foo-mytopic # IS THIS ALLOWED?
I've tried this before, and it seems to work, but it's a bit strange because I have now checked out code that was in the foo manifest, but my current manifest branch is bar. What are the implications of being on a different branch than that described in the manifest?
Note: I've read this, and I think my question is different. I know how to switch branches. I'm interested in the implications of being on a different branch than the one described in the current manifest and how this might affect my workflow.
Since no one else was able to answer this, I did some more research and experimentation. Here is what I have found:
Tl;dr - Certain commands will do weird things. Be careful when using repo sync
and repo start
. Try to stick to plain git commands. repo upload
should work.
The repo documentation says that repo sync is equivalent to
$ git fetch origin
$ git rebase origin/<BRANCH>
where BRANCH is the currently checked-out branch in the local project directory. However, based on my own experience, repo will also mess with the upstream tracking information for that branch based on what is in the current manifest.
To continue the example from above, git checkout foo-mytopic
is, in fact, allowed, and will kind of behave appropriately. Repo upload will push changes to the branch that foo-mytopic
is tracking (foo
), but repo sync would change the upstream tracking information. In this situation, may be better to manually run git fetch origin
and git rebase origin/<BRANCH>
.
The manifest (and branch) described by repo init will not come into play again until repo sync
or repo start
is run.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With