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?
In fact, it seems that this problem is (potentially) due to the combination of various factors:
- I have actually renamed a branch (but that doesn't seem to be the major causek)
- I have also updated username and email address (this can support the analysis that I have performed various operations as some other user)
- 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:
- Removing the denied file using the command
rm -f .git/FETCH_HEAD
(as described in this answer) - 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