Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pushing to a remote branch (failed to update ref)

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 [email protected]:bluefirelabs/fire-voice-droid.git
 ! [remote rejected] feature/initial-change -> feature/initial-change (failed to update ref)
error: failed to push some refs to '[email protected]:bluefirelabs/fire-voice-droid.git'

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

like image 287
skbrhmn Avatar asked May 11 '16 22:05

skbrhmn


1 Answers

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
like image 198
richieB Avatar answered Sep 17 '22 15:09

richieB