I'm used to using git
with a single repository. However, I've lately been dabbling with Android development and am trying to wrap my head around repo
. I have set up some custom git repos by creating xmls in the .repo/local_manifests
directory (I'm using repo 1.19) and repo sync
works fine.
When I look at the custom git repos they say # Not currently on any branch.
This looks just like when I use a command like git checkout abcd1234
(to check out commit abcd1234) rather than git checkout origin/master
. As far as making changes, I'm not sure how to push back to origin. Here's my normal git workflow.
git checkout origin/master
#make changes to working directory
git add .
git commit -m 'useful message'
#assume time has passed and there could be changes upstream
git fetch
git rebase origin/master
git push origin master
Now that I'm no longer technically on a branch, how can I push changes? I know there is a tool repo upload
but I'm not exactly sure how it works. I've never used Gerrit, but maybe it would be worth setting up so other team members can review code before it gets pushed to Github. Honestly I still have a very abstract understanding of repo
and Gerrit
.
Technically, if you do
git checkout origin/master
you immediately get into detached HEAD state.
For better or worse, this is exactly what repo sync
does by default - such that every one of your repositories listed in manifest is in detached HEAD state after fresh repo sync
.
Detached HEAD is perfectly normal state for repo
- if origin/master moves forward, repo sync
will also move your local state (effectively it does git checkout origin/master
again).
However, this weird state is not good if you want to make your own changes and push them upstream. In this case, you can do one of the following:
repo start master .
which means start tracking branch called master
in current project (.
).
Alternatively, you can use (and I prefer this, actually):
git checkout --track origin/master
Both methods will give you almost identical result: you no longer will be in detached HEAD state, but on local branch which will be tracking remote branch.
At this point, you can make local commits and push them directly upstream using standard git push
(but this may not be permitted by server policy) or you can submit for Gerrit code review (highly recommended and is default choice for most Android shops).
Once tracking branch is in place, submitting to Gerrit is as simple as
repo upload # upload changes in multiple repositories at once
or
repo upload . # upload changes in current git repo only, fast!
(this assumes that your manifest contains proper settings for review server).