warning: ignoring broken ref refs/remotes/origin/HEAD
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/main
orgit symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/main
orgit 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 origin
git branch -u origin/main main
, reset branch upstream
I encountered this recently when someone on my team deleted our old development branch from the remote. I ran this command to check the status of HEAD:
$ git symbolic-ref refs/remotes/origin/HEAD
refs/remotes/origin/old_dev
This command output the name of the old development branch, which no longer exists.
I fixed the warnings using this:
$ git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/new_dev
(Where "new_dev" is a branch name. Replace it with the name of the branch you want HEAD to point to.)
Just run the command -
#replace the <branch name> with your main branch - master, main, etc.
git remote set-head origin <branch name>
Enjoy!
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.