Pushing to a remote branch (failed to update ref)

匿名 (未验证) 提交于 2019-12-03 07:36:14

问题:

I have a remote repository with a feature/initital-change branch. Now I want to push some files to this remote branch from my local feature/initital-change branch.

I went through a few posts on pushing to remote branches and tried out a few methods but I am still getting the same error. After adding and committing, I get the following for git status.

Sakibs-MacBook-Pro:BluFireLabs SakibArRahman$ git status On branch feature/initial-change Your branch is ahead of 'origin/feature/initial-change' by 1 commit.   (use "git push" to publish your local commits) nothing to commit, working directory clean 

But when I push, I get the following:

Sakibs-MacBook-Pro:BluFireLabs SakibArRahman$ git push origin feature/initial-change Counting objects: 255, done. Delta compression using up to 4 threads. Compressing objects: 100% (141/141), done. Writing objects: 100% (255/255), 6.57 MiB | 1.88 MiB/s, done. Total 255 (delta 49), reused 13 (delta 5) remote: error: Cannot update the ref 'refs/heads/feature/initial-change': unable to create directory for logs/refs/heads/feature/initial-change: No such file or directory To git@bitbucket.org:bluefirelabs/fire-voice-droid.git  ! [remote rejected] feature/initial-change -> feature/initial-change (failed to update ref) error: failed to push some refs to 'git@bitbucket.org:bluefirelabs/fire-voice-droid.git' 

Any idea on how I can fix this or what I am doing wrong? Thanks in advance!

回答1:

This can happen when two branches are created, one with a slash / and one without a slash, where the branch without the slash is the prefix of the other branch.

Example

Consider these two valid branch names:

  • feature
  • feature/initial-change

When you fetch these branches from the remote to your local machine the feature branch is represented as a file and the feature/initial-change branches is represented as a directory named feature and a file named initial-change. Your OS cannot create a file and directory of the same name:

  • logs/refs/heads/feature
  • logs/refs/heads/feature/initial-change

Workaround

The workaround would be to delete the feature branch in this case:

git push --force origin :feature 


回答2:

I was also seeing this error and it was to do with premissions in my Git bare repo ref/heads folder not being set correctly.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!