Push to refs/heads/branch = "Can not update the reference as a fast forward"

3,545 views
Skip to first unread message

Mateusz Grzechociński

unread,
Aug 17, 2012, 11:26:05 AM8/17/12
to repo-d...@googlegroups.com
Hi Gerrit users!

I have a question about pushing to remote branches and gerrit access configuration.

I have a remote branch called XYZ. By git fetch and git checkout I have local 'shadow' branch with one additional commit I want to push to remote repo.

mgrzechocinski@mghp:~/dev/app[XYZ]$ git status
# On branch XYZ
# Your branch is ahead of 'origin/XYZ' by 1 commit.
#
nothing to commit (working directory clean)

Now trying to push:

mgrzechocinski@mghp:~/dev/app[XYZ]$ git push origin HEAD:refs/heads/XYZ
Counting objects: 3, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 307 bytes, done.
Total 2 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1)
remote: Processing changes: refs: 1, done    
To ssh://gerrit/app.git
 ! [remote rejected] HEAD -> XYZ (can not update the reference as a fast forward)
error: failed to push some refs to 'ssh://gerrit/app.git'

What am I doing wrong? What this message means? I'm just trying to push one simple commit which parent is same as remote HEAD.
In Gerrit admin panel, my group has access to Push.

Thanks ins advance for any hints.

-- 
Matthew

Magnus Bäck

unread,
Aug 17, 2012, 11:34:02 AM8/17/12
to repo-d...@googlegroups.com
On Friday, August 17, 2012 at 11:26 EDT,
Mateusz Grzechociński <mateusz.gr...@gmail.com> wrote:

[...]

> mgrzechocinski@mghp:~/dev/app[XYZ]$ git push origin HEAD:refs/heads/XYZ
> Counting objects: 3, done.
> Delta compression using up to 2 threads.
> Compressing objects: 100% (2/2), done.
> Writing objects: 100% (2/2), 307 bytes, done.
> Total 2 (delta 1), reused 0 (delta 0)
> remote: Resolving deltas: 100% (1/1)
> remote: Processing changes: refs: 1, done
> To ssh://gerrit/app.git
> ! [remote rejected] HEAD -> XYZ (can not update the reference as a
> fast forward)
> error: failed to push some refs to 'ssh://gerrit/app.git'
>
> What am I doing wrong? What this message means? I'm just trying to
> push one simple commit which parent is same as remote HEAD.
> In Gerrit admin panel, my group has access to Push.

Gerrit doesn't think that the commit you're pushing is based on the
current branch tip. You can easily verify this by fetching from the
server ("git fetch origin"). As I'm sure this will reveal, your XYZ
remote branch wasn't up to date since it was updated by the fetch.
Use "git rebase origin/XYZ" to rebase your commit on top of the
updated remote branch. That should enable you to push.

--
Magnus Bäck
ba...@google.com

Edwin Kempin

unread,
Aug 20, 2012, 3:47:21 AM8/20/12
to repo-d...@googlegroups.com
The problem can also be that you are trying to bypass code-review without having the access right to do direct pushes.
It looks like you are pushing to refs/heads/XYZ which is a direct push, if you want to push your commit for code review push to refs/for/XYZ.

For this situation the error message is wrong and misleading. In the current tip of master this is fixed by [1].

[1] https://gerrit-review.googlesource.com/37250

2012/8/17 Magnus Bäck <ba...@google.com>

Mateusz Grzechociński

unread,
Aug 20, 2012, 4:38:36 AM8/20/12
to repo-d...@googlegroups.com
Hi folks,

thanks for your help.
I've already done what Magnus said, but i think that my branch is already up to date and my problem is somewhere else.

See the log:
mgrzechocinski@mghp:~/dev/app[XYZ]$ git fetch
mgrzechocinski@mghp:~/dev/app[XYZ]$ git rebase origin/XYZ
Current branch XYZ is up to date.
mgrzechocinski@mghp:~/dev/app[XYZ]$ git push origin HEAD:refs/heads/XYZ
Counting objects: 3, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 307 bytes, done.
Total 2 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1)
remote: Processing changes: refs: 1, done    
To ssh://agerrit/app.git
 ! [remote rejected] HEAD -> XYZ (can not update the reference as a fast forward)
error: failed to push some refs to 'ssh://agerrit/app.git'

W dniu poniedziałek, 20 sierpnia 2012 09:47:21 UTC+2 użytkownik Edwin Kempin napisał:
The problem can also be that you are trying to bypass code-review without having the access right to do direct pushes.
It looks like you are pushing to refs/heads/XYZ which is a direct push, if you want to push your commit for code review push to refs/for/XYZ.
For this situation the error message is wrong and misleading. In the current tip of master this is fixed by [1].

Well, that may be a hint. What do you mean by "having the access right to do direct pushes.".
Is is that?

test/developers is a group I'm a member of. But still "can not update the reference as a fast forward".

Matthew 

Mateusz Grzechociński

unread,
Aug 20, 2012, 7:46:41 AM8/20/12
to repo-d...@googlegroups.com
Ok, I've reviewed my project access table and eventually found that I've added grants to group which I was not a member.
As Edwin said, this message is misleading and I had no clue that it may be connected with wrong access rights for particular user.

EOT. Thanks for your help.
Reply all
Reply to author
Forward
0 new messages