Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git push fails to push to origin - no such ref

I'm having trouble pushing commits on a hotfix branch created with git-flow to the remote repository.

Here is the error:

$ git push origin hotfix/MyHotfix
Counting objects:
... etc
To {my remote repo}
 ! [remote rejected] hotfix/MyHotfix -> hotfix/MyHotfix (no such ref)
error: failed to push some refs to {my remote repo}

I created the hotfix with the standard syntax:

git flow hotfix start MyHotfix

and this branch is already present on the origin, which I can see with git branch -a. I have also checked that the branch is still present on the remote server, since it shows up when I run git remote show origin.

Has anyone come across this before with git or git-flow and found a solution?

Note - things I have tried:

  • Re-cloning the remote repo -> same error
  • Deleting the local branch -> same error
  • Deleting the remote branch -> I can push the 'new' branch, but get the same error on my colleagues local repo when he tries to push a commit (after git remote prune origin)
  • Force push -> same error
  • Upstream push -> same error
  • Checking refs -> my commit parent id matches the server

Update:

git ls-remote origin and git show-ref show different refs for the local and remote hotfix branches, but this is because I have 1 extra commit locally, and the parent commit's ref matches the ref on origin.

like image 288
Laurence Avatar asked Oct 05 '22 02:10

Laurence


2 Answers

It looks like it was actually a problem with the server repository. Running these steps on the bare repo on the server cleared up the error:

git fsck --full
git prune
git gc

Note: according to the man pages git prune isn't required because git gc calls it, but I was trying everything.

like image 69
Laurence Avatar answered Oct 10 '22 03:10

Laurence


Considering issue 92, I don't think hotfix branches are meant to be published.
This is a feature request which is still pending.

While release and feature branches can all be published (git flow release/feature publish), hotfix branches cannot.

So maybe the push itself has been prevented to be compliant with the (already denied) publish operation.

like image 21
VonC Avatar answered Oct 10 '22 04:10

VonC