Vikram
Vikram

Reputation: 4192

Git via Gerrit: local/master out of sync with origin/master

There are several questions opened against "Your branch is ahead of 'origin/master' by X commits."... However, I could not fix from the solutions I provided.

Here is my scenario:

I have a working gerrit environment and I have the privileges to bypass review.

git status yields:

# On branch master
# Your branch is ahead of 'origin/master' by 3 commits.
#
nothing to commit (working directory clean)

on seeing my branch is ahead of remote I try to push my branch.

git push gerrit:project master
Everything up-to-date

So I try to pull

git pull gerrit:project

From gerrit:project

* branch HEAD -> FETCH_HEAD

Already up-to-date.

git status again yields the same status of my branch ahead of 'origin/master' by X commits

when I diff master origin/master I get no changes.

Please let me know if I can assist you with outputs of other commands..

thanks for looking at this.

Upvotes: 2

Views: 2433

Answers (2)

Eddie
Eddie

Reputation: 1536

git push -f didn't seem to do anything for me. Here's what worked in my case.

git reset --hard HEAD~n

Replace n with how ever many commits your ahead by. Sometimes it takes a few times.

git pull

You should be at the correct location in the repo now without being 'related' to other commits in Gerrit.

Upvotes: 0

Vikram
Vikram

Reputation: 4192

I posted a different question on this forum and the answer to that question is related to this one as well.

To summarize here are some steps that can be done:

Consider using push -f

or delete "remotes" and update it like this:

git remote -v throws output

origin  gerrit:project (fetch)
origin  gerrit:project (push)

From gitref add your remotes here and remove origin

git remote add gerrit gerrit:project git remote rm origin git remote -v which should show following:

gerrit  gerrit:project (fetch)
gerrit  gerrit:project (push)

Here is the reference to that question of my mine...which has been answered.

Please feel free to close as I think this would be duplicate of my other question

Upvotes: 1

Related Questions