0

Every time I checkout to a review branch using git-review like:

j ❯❯❯ git-review -d 5779
Downloading refs/changes/79/5779/1 from gerrit
Switched to branch "review/jezor/5779"

the status command tells me I'm way ahead the gerrit/master branch:

j ❯❯❯ git status
On branch review/jezor/5779
Your branch is ahead of 'gerrit/master' by 364 commits.
  (use "git push" to publish your local commits)
nothing to commit, working tree clean

So I checked out to the gerrit/master branch:

j ❯❯❯ git checkout gerrit/master
Note: checking out 'gerrit/master'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b <new-branch-name>

HEAD is now at cb563f2e... Old, old commit from six months ago

And then tried rebasing current master and pushing new changes to it:

j ❯❯❯ git pull --rebase origin master
From ssh://my.projects.review:29418/some_project
 * branch              master     -> FETCH_HEAD
First, rewinding head to replay your work on top of it...
Fast-forwarded HEAD to dcf5ac6807455dcca33e288d830515c6bfe89aa0.

j ❯❯❯ git push origin HEAD:gerrit/master
error: unable to push to unqualified destination: gerrit/master
The destination refspec neither matches an existing ref on the remote nor
begins with refs/, and we are unable to guess a prefix based on the source ref.
error: failed to push some refs to 'ssh://jezor@my.projects.review:29418/some_project'

... as you can see, unsuccessfully.

It doesn't bother me or my team much, as we are used to it. It would be nice to keep the repository clean though. I am guessing this line in git-review script is responsible for this behavior (setting upstream to gerrit/master instead of master).

Why is this branch so far behind?

Can I update it somehow?

Otherwise, can I get rid of it completely?

Jezor
  • 2,330
  • 1
  • 15
  • 38

1 Answers1

1

First of all, let clarify the difference between "master" and "gerrit/master" terms:

  • master = is the local branch called master (only present in your local repository) which is updated if you execute commands like "git commit", "git merge" or "git rebase".

  • gerrit/master = is the local representation of a remote branch called master (accessible for everyone who clone the repository) which is updated everytime you execute the "git fetch" command. the "gerrit" term points to a remote repository. Probably the "gerrit" remote was created automatically by git-review because this is the default name when the "defaultremote" property is not explicity defined in the ".gitreview" git-review configuration file.

Things to check:

  • The definitions in .gitreview file
  • The result of the "git remote -v" command
  • The result of the "git remote show gerrit" and "git remote show origin" commands.
  • We do work on the `master` branch, and we push changes to `refs/for/master` - a gerrit representation of `master` branch. I am unsure what the `gerrit/master` branch is for. It seems to be fetched only by `git-review`. – Jezor Mar 22 '17 at 23:27
  • gerrit/master is a local representation of the remote master branch, it's created automatically by git-review. To update your gerrit/master just execute: "git fetch gerrit". The gerrit/master should point to the master branch commit. – Marcelo Ávila de Oliveira Mar 24 '17 at 11:32
  • Hm, why is it so far behind then? Even right after I clone the project... – Jezor Mar 25 '17 at 19:24
  • gerrit/master is behind Change 5779... Is change 5779 based on master? Or in another branch? – Marcelo Ávila de Oliveira Mar 25 '17 at 19:35
  • It is indeed based on `master`. – Jezor Mar 25 '17 at 20:24
  • Also, `defaultbranch` property in my `.gitreview` file is set to `master` – Jezor Mar 25 '17 at 20:25
  • 1
    What is the defaultremote property value? – Marcelo Ávila de Oliveira Mar 25 '17 at 23:45
  • It's not set up, but `git-review` pushes to origin on other projects that are set up the same way. I prefer more verbose `git push HEAD refs/for/master` because I know exactly what is going on and choose to push a draft. – Jezor Mar 26 '17 at 02:54
  • Interestingly, adding `defaultremote=origin` to .gitreview solved the problem. Thank you for the clue! Please update your answer so I can accept it (: – Jezor Mar 26 '17 at 03:27