13

I have a base repository that lives on a UNC \machine\share ....etc. I have a local clone that I work on in the master branch and occasionally merge over to the "stable" branch.

usually I do a git push --all

to move all changes in all branches up to the server. After creating a new branch git branch MultiCompany

and then pushing it to the server git push --all

which creates the branch on the server also. I did some work, committed all the changes in multicompany branch and then tried to do a git push --all

and got the following error:

cdturner@OAHU ~/desktop/git sourcetree/maerekai.web.framework (multicompany) 
$ git push --all
Counting objects: 28, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (22/22), done.
Writing objects: 100% (23/23), 11.34 KiB, done.
Total 23 (delta 8), reused 0 (delta 0)
Unpacking objects: 100% (23/23), done.
error: Ref refs/heads/multicompany is at bd5a32df35ce8d5ae30ce999af34c4c5f35581df but expected 0000000000000000000000000000000000000000
remote: error: failed to lock refs/heads/multicompany
To //pluto/users/cdturner/Git repositories/Maerekai.web.framework.git
 ! [remote rejected] multicompany -> multicompany (failed to lock)
error: failed to push some refs to '//pluto/users/cdturner/Git repositories/Maerekai.web.framework.git'

I tried to back out the last commit withgit reset --hard HEAD^

and then retried the push.....

cdturner@OAHU ~/desktop/git sourcetree/maerekai.web.framework (multicompany)
$ git push --all
Total 0 (delta 0), reused 0 (delta 0)
error: Ref refs/heads/multicompany is at bd5a32df35ce8d5ae30ce999af34c4c5f35581df but expected 0000000000000000000000000000000000000000
remote: error: failed to lock refs/heads/multicompany
To //pluto/users/cdturner/Git repositories/Maerekai.web.framework.git
 ! [remote rejected] multicompany -> multicompany (failed to lock)
error: failed to push some refs to '//pluto/users/cdturner/Git repositories/Maerekai.web.framework.git'`
Hannele
  • 9,301
  • 6
  • 48
  • 68
Chris Turner
  • 131
  • 1
  • 1
  • 3

4 Answers4

15

For the record, I believe the root cause of this problem was the difference in capitalisation between the local and remote branch names, and the case-insensitive nature of the Windows share that hosted the remote repository.

We just encountered this exact same error and were able to resolve the problem simply by renaming the local branch to match the capitalisation of the existing remote branch.

See here how to rename a local branch.

In Windows, due to capitalization, you may need to take two steps:

git branch -m example foo
git branch -m foo EXAMPLE
Community
  • 1
  • 1
A.L.
  • 760
  • 5
  • 13
  • Thank you! Same problem here... thanks to you comment I will finnaly be able to fix the problem I got here :) – Guillermo Aug 04 '11 at 17:20
  • I wasn't able to rename using SourceTree ("branch already exists...)", so I renamed to a temporary branch name, deleted from .git/refs/heads the folder having the incorrect capitalization, and then renamed the branch back to use the correct capitalization. – Carl G Jun 10 '13 at 19:13
  • When I tried this I got the error message "fatal: A branch named already exists." So I used the "-M" switch instead. – GeekyDaddy Jun 07 '18 at 14:48
6

do a git fsck --full on the remote repo. The remote repo may have become corrupt. Clone another one from the remote. Replace the original remote with this one. You should now be able to push again. Something has happened to the remote repo. Nothing you're doing is out of line with regular use.

Adam Dymitruk
  • 124,556
  • 26
  • 146
  • 141
5

An error I found was trying to push a branch develop to a repository that had branches named: develop/1148 and develop/693. git isn't ok with this (I forget why), so deleting those branches (if possible) fixed this hangup.

hjc1710
  • 576
  • 4
  • 17
  • 1
    This was the solution for me. I was trying to push `dev` when an ancient branch called `dev/rob` existed on the remote. Running `git push origin :dev/rob` first fixed it. – robbles May 08 '14 at 21:46
  • Worked for me too. Was trying to push a branch called release/patch1 when a branch named release already existed on the remote. – Kyle Fransham Jul 24 '14 at 15:02
  • 1
    Git disallows having a branch, a branch folder, and a tag with the same name. TIL – Hannele Oct 16 '15 at 14:25
3

Thanks, git fsck --full reported "dangling commit"

so git prune blew away the offending stuff and I got to type it in again. Btu at least the trees are all resolved..

Thanks for the help.