Search code examples
gitgit-flowhotfix

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.


Solution

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