'warning: ignoring broken ref refs/remotes/origin/HEAD
Since a few days ago, every time I press tab key to complete branch names in bash I see the message:
warning: ignoring broken ref refs/remotes/origin/HEAD warning: ignoring broken ref refs/remotes/origin/HEAD
For example, this is what I see when I have a branch called feature/foo and I press tab:
git checkout f
$ git checkout fwarning: ignoring broken ref refs/remotes/origin/HEAD
warning: ignoring broken ref refs/remotes/origin/HEAD
eature/
Solution 1:[1]
This is a simpler solution than symbolic-ref.
Since you may have excluded the branch that origin/HEAD was initially pointed to.
1. List your remote branches with:
git branch -r
2. If it doesn't show in the results:
origin/HEAD -> origin/(something)
3. Just point it again with:
git remote set-head origin master
where "master" is the name of your primary (head) branch.
Running git branch -r again now shows origin/HEAD -> origin/(something) and the warning goes away.
Solution 2:[2]
Just run the command -
#replace the <branch name> with your main branch - master, main, etc.
git remote set-head origin <branch name>
Enjoy!
Solution 3:[3]
Some problems arise after the local master renames main:
git fetch: "fatal: couldn't find remote ref refs/heads/master";git branch -u origin/main main: "error: the requested upstream branch 'origin/main' does not exist";git remote set-head origin main: "error: Not a valid ref: refs/remotes/origin/main";git push -u origin main: "error: failed to push some refs to 'github.com:/.git'";git symbolic-ref HEAD refs/heads/mainorgit symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/mainorgit update-ref refs/heads/main main,- and then
git branch -r: "warning: ignoring broken ref refs/remotes/origin/HEAD";
- and then
The solution to this problem:
git remote -v, copy git repository urlgit remote rm origin, remove remotegit remote add origin <REPOSITORY_URL>, reset remote urlgit fetch origingit branch -u origin/main main, reset branch upstream
Solution 4:[4]
In my case the problem was the file .git\refs\remotes\origin\master that got corrupted, maybe since my computer was involuntary disconnected from power a few days ago.
I solved it by replacing the file content with the correct reference, a 40 char hex number that can be found in the file .git\FETCH_HEAD.
Solution 5:[5]
Looks like the default branch of your remote origin doesn't exists anymore.
Fix the default branch of the remote:
- GitHub: https://github.com/USER_OR_ORG/REPOSITORY/settings/branches -> "Default branch"
- Bitbucket Cloud: https://bitbucket.org/USER_OR_ORG/REPOSITORY/admin -> " Main branch"
- Bitbucket Server: http://git.sid.distribution.edf.fr/projects/PROJECT/repos/REPOSITORY/settings -> "Default branch"
Solution 6:[6]
My solution was to delete the folder/file:
./.git/refs/remotes/origin/{branch_name}
Afterwards I was finally able to make a git fetch again.
Solution 7:[7]
Like already answered - The warning indicates that the remote branch no longer exists, e.g. when the remote branch is merged+deleted into another branch.
In my case I had to delete my local branch, because it was not longer needed and fixing the broken ref was not possible. Therefore, git branch -d feature/.. did the job.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Paulo Coghi |
| Solution 2 | |
| Solution 3 | |
| Solution 4 | user7359564 |
| Solution 5 | zigarn |
| Solution 6 | chrisaramar |
| Solution 7 | Kevin Wallis |
