3

I am struggling to understand repo and git. I have created a branched manifest.xml file that specifies <default revision="project/master"… />

Everything works fine but when the repo sync is complete there is no indication that each project is on that branch. git branch in each project says you aren't on a branch. However if you run gitk, you can see that you are at the correct revision.

repo checkout project/master says that none of the projects have this branch defined. The output of git checkout project/master in a project directory looks like a new branch was created.

If I git clone project; git checkout project/master, then everything is as expected.

Questions:

  1. What is different about what repo is doing?

  2. I am trying to define a "new" master branch for our project. Am I really on that branch even though repo and git do not indicate that?

Please help me to understand so that I can put my mind at ease…

TIA

Thanatos
  • 37,926
  • 14
  • 76
  • 136
acurtis
  • 131
  • 2
  • 7

2 Answers2

3

This is expected. Repo doesn't create a local branch for the remote branch you've listed in the manifest. It's up to you to create a local branch with repo start (or the equivalent underlying Git command that repo start is just a wrapper of). Repo just checks out the commit that the manifest points to, creating a detached head.

In Git, remote branches can't be checked out for work. All work (i.e. all changes) takes place on local branches. When you ran

git clone project
cd project
git checkout project/master

the literal meaning of the last command is "check out the branch that matches the project/master pattern, which in the case of a matching remote branch will cause it to be checked out as a detached head", but Git did what it thought you actually meant which is

git checkout project/master origin/project/master

which creates the local branch project/master based on the origin/project/master remote branch.

Repo's behavior might seem weird, but the intended workflow is that you create topic branches for each little thing you're working on. Repo doesn't know what you're going to work on in a particular git (if at all) so creating branches for you would be presumptuous.

Also, keep in mind that the manifest doesn't necessarily point to branches. The revision attribute could point to tags or even SHA-1s, and creating local branches for them wouldn't make sense.

Magnus Bäck
  • 10,535
  • 3
  • 40
  • 57
0

While repo start <branch_name> --all must use same branch name on each git repo, it is not suitable for manifest with different revision (remote branch).

I found a great solution from this post using repo forall.

You can use the following flow to make sure each sub git repo is not in headless state and tracking with same branch.

repo init <...>
repo sync
repo forall -pc 'git checkout --track $REPO_REMOTE/$REPO_RREV'

You can check repo forall page for environment variable definition.