Cannot open FETCH_HEAD after renaming a branch

社会主义新天地 提交于 2019-12-08 03:33:17

问题


After having renaming the 'master' branch (using Sourcetree), I can't fetch anymore the changes done in the remote repository.

I get the error:

error: cannot open .git/FETCH_HEAD: Permission denied

When I open this file, I see that the referenced branch is still set toward branch 'master'.

Taking a look at the remote repository, I saw that a branch with named 'master' still exists, in addition to the renamed branch where I merged my last changes. I think there have got a problem somewhere and the renaming was not replicated correctly in the remote repository.

I have tried to manually edit the FETCH_HEAD (changing the full SHA and the pointed branch), but I still get this error. Of course, I can not rename again as before my main branch, since a branch named 'master' is always present.

Is there a way around this problem?


回答1:


In fact, it seems that this problem is (potentially) due to the combination of various factors:

  1. I have actually renamed a branch (but that doesn't seem to be the major causek)
  2. I have also updated username and email address (this can support the analysis that I have performed various operations as some other user)
  3. Some branches was unable to be fetched certainly because of a known bug of SourceTree (which have suddenly stopped tracking of some remote branches)

As using chown command doesn't seem to be effective, I have finally resolved my issue using the following process:

  1. Removing the denied file using the command rm -f .git/FETCH_HEAD (as described in this answer)
  2. Reconnecting the untracked branches using the command git branch -u (as described in this comment)

After that, I was able to fetch all the remote branches, and now, all is correctly synchronized with my local repository.



来源:https://stackoverflow.com/questions/45825563/cannot-open-fetch-head-after-renaming-a-branch

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