1

I get the following error when I try to git push a branch documentation/manifest:

error: update_ref failed for ref 'refs/remotes/origin/documentation/manifest': cannot lock ref 'refs/remotes/origin/documentation/manifest': 'refs/remotes/origin/documentation' exists; cannot create 'refs/remotes/origin/documentation/manifest'

The steps which led up to this error were:

  1. cloned from the remote repo (github)
  2. created a local branch documentation/manifest and did some work on it, committing the work.
  3. pushed the branch. Couldn't push because there was an existing 3 year old, stale, branch called documentation.
  4. Deleted the branch documentation on github.
  5. pushed again. Branch pushed OK to remote, I can confirm it is there, however the above error appears after every time I push. Given that I presume it is a local error.

I've looked up some similar questions such as Git error when pushing - update_ref failed, however this was dealing with a different cause - it was not clear to me if the suggested solutions to that answer would help in this case, and as they seemed quite low-level they could equally well mess things up in a different way.

So, what do I need to do to get rid of this error whenever I push this branch?

Euan Smith
  • 2,102
  • 1
  • 16
  • 26

1 Answers1

2

I believe the problem is that you still have a local reference to the former remote documentation branch, because the error messages says cannot create 'refs/remotes/origin/documentation/manifest', which would indeed be the case if refs/remotes/origin/documentation already exists as a regular file.

Removing the old local references should solve this problem:

git fetch -p

And if that doesn't work, you can even manually delete the problem file:

rm .git/refs/remotes/origin/documentation

which you know is safe, since you deleted the documentation branch on origin.

Relevant reference:

joanis
  • 10,635
  • 14
  • 30
  • 40