This error occurs if the default branch on the remote repository has been deleted. The owner of the repository can fix this for everyone, or the user cloning can fix their local repository.
Detecting this error is simple, git will warn you when you clone the repository:
git clone https://github.com/user/repo.git # Clone a repo # Cloning into 'repo'... # remote: Counting objects: 66179, done. # remote: Compressing objects: 100% (15587/15587), done. # remote: Total 66179 (delta 46985), reused 65596 (delta 46402) # Receiving objects: 100% (66179/66179), 51.66 MiB | 667 KiB/s, done. # Resolving deltas: 100% (46985/46985), done. # warning: remote HEAD refers to nonexistent ref, unable to checkout.
You can also verify that you do not have a branch checked out after clone:
cd repo git branch # [no output]
To fix a local repository, check out the branch you wish to work in:
git branch -a # List ALL the branches # remotes/origin/master git checkout master # Create and checkout a tracking branch # Branch master set up to track remote branch master from origin. # Switched to a new branch 'master'
You'll need to change the default branch of the repository.