I am revisiting a collaborative portfolio project in Java/Spring and I have run into an issue on my local machine that I may have created a month ago. At some point I must have created HEAD 2 of refs/remotes/origin/HEAD 2
. Now when I am trying to fetch origin I am receiving this error from github desktop (Edits in "<<>>"):
From github.com:<<myGithub>>/<<repoName>>
- [deleted] (none) -> origin/HEAD 2
fatal: bad object refs/remotes/origin/HEAD 2
error: github.com:<<myGithub>>/<<repoName>>.git did not send all necessary objects
Upon attempting to troubleshoot, I attempted a couple git actions, perhaps naively that have dug me deeper. I used git remote set-head origin main
and here were the results:
% git remote set-head origin main
% git branch --all
warning: ignoring ref with broken name refs/remotes/origin/HEAD 2
* cdev
david
erik
kern
main
remotes/origin/HEAD -> origin/main
remotes/origin/david
remotes/origin/erik
remotes/origin/kern
remotes/origin/main
Note: The 5 last lines preceded with 'remotes/origin' are displayed in red, with the exception of -> origin/main
% git remote show origin
* remote origin
Fetch URL: git@github.com:<<myGithub>>/<<repoName>>.git
Push URL: git@github.com:<<myGithub>>/<<repoName>>.git
HEAD branch: cdev
Remote branches:
cdev new (next fetch will store in remotes/origin)
david tracked
erik tracked
kern tracked
main tracked
refs/remotes/origin/HEAD 2 stale (use 'git remote prune' to remove)
Local branches configured for 'git pull':
cdev merges with remote cdev
david merges with remote david
erik merges with remote erik
kern merges with remote kern
main merges with remote main
show merges with remote main
Local refs configured for 'git push':
cdev pushes to cdev (up to date)
david pushes to david (up to date)
erik pushes to erik (up to date)
kern pushes to kern (up to date)
main pushes to main (up to date)
I'd like clarity in what to take from this: cdev new (next fetch will store in remotes/origin)
My attempts to heed refs/remotes/origin/HEAD 2 stale (use 'git remote prune' to remove)
have been fruitless as well.
% git remote prune origin --dry-run
Pruning origin
URL: git@github.com:<<myGithub>>/<<repoName>>.git
* [would prune] origin/HEAD 2
% git remote prune origin
Pruning origin
URL: git@github.com:<<myGithub>>/<<repoName>>.git
* [pruned] origin/HEAD 2
% git remote prune origin --dry-run
Pruning origin
URL: git@github.com:<<myGithub>>/<<repoName>>.git
* [would prune] origin/HEAD 2
Note: Pruning doesn't appear to be effective; going in a circle.
I suspect that the issue could have arisen from the improper or sloppy reuse of my named branch after merging it to the cdev branch. I feel I'm going the wrong direction with this and will be diving into git documentation before I try anything else bold.
Could anyone steer me the right direction to clean up this mess? I guess I'm looking for clarity to which action would cause this, and thusly what I should NOT do in the future. Overall I'm asking: what steps can be taken to clean up my remotes and remove any reference to HEAD 2? Furthermore, I am most interested in correcting this with git commands rather than clever work-arounds.
I was able to correct the error with the following CLI command:
rm .git/refs/remotes/origin/HEAD\ 2