Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does git push work with android's repo tool?

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.

like image 223
redbmk Avatar asked Jan 26 '13 18:01

redbmk


People also ask

How does Git push work?

The git push command is used to upload local repository content to a remote repository. Pushing is how you transfer commits from your local repository to a remote repo. It's the counterpart to git fetch , but whereas fetching imports commits to local branches, pushing exports commits to remote branches.

How do I push to a Git repository?

In the command line, navigate to the root directory of your project. Initialize the local directory as a Git repository. To create a repository for your project on GitHub, use the gh repo create subcommand. When prompted, select Push an existing local repository to GitHub and enter the desired name for your repository.

How does repo sync work?

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.


1 Answers

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).

like image 66
mvp Avatar answered Sep 21 '22 12:09

mvp