3

I've looked for a solid answer on this, and haven't really found anything relevant. We are working with a remote git repository where we are pushing branch that is not master to the remote repo. For example:

git checkout -b new_branch
git add --all .
git commit -m "changes"
git push remote new_branch

However, when we try to clone from that bare remote repository, we get the error:

git clone /path/to/repo.git 

warning: remote HEAD refers to nonexistent ref, unable to checkout.

I'm not sure why HEAD is detached and not pointing to the last commit on new_branch? How can we clone this remote repository?

ossys
  • 4,157
  • 5
  • 32
  • 35
  • Is the name of your remote "remote"? – isherwood May 11 '15 at 17:56
  • Does `remote` have a master branch? Perhaps you want to [change the default branch on remote](https://feeding.cloud.geek.nz/posts/setting-default-git-branch-in-bare/)? – Tony May 11 '15 at 18:00
  • What does the output of `git branch -a` show, if anything, for `remotes/origin/HEAD` (or whatever the name of the remote is)? – chepner May 11 '15 at 18:05
  • Yes, the name of the remote repo is "remote". The remote repo does not have any repository on it, we are essentially pushing a brand new repo remotely to it. There is no master branch we are pushing up to the remote repository. – ossys May 11 '15 at 18:14

2 Answers2

1

The warning: remote HEAD refers to nonexistent ref, unable to checkout. means that the remote (bare) repository contains branch reference in the file HEAD that does not match any published branch in the same repository.

Note that the warning only means that git didn't do checkout. The cloned repository is otherwise just fine. Just do git branch -a to see possible branches and git checkout the-branch-you-want to workaround the issue.

This usually happens because the default contents for that file is ref: refs/heads/master which says that if somebody is going to clone this repository, they should by default clone the branch refs/heads/master. By default Git will create local branch without the refs/heads/ prefix (that is, master by default). Try git help symbolic-ref for more information.

The problem with this situation is that Git does not provide a method for modifying remote symbolic refs so either you use something the Git hosting provider has implemented (e.g. Settings - Default branch in GitHub if you have admin rights) or you have to use branch name master as the default branch (because that's the default value for that symbolic ref).

One way to hit this issue is to create a new remote bare repo with no commits and then do git push name-of-the-remote my-special-branch-name which will result in bare repository containing a single branch my-special-branch-name but the HEAD symbolic ref still contains the default value pointing to master. As a result, you'll get the aforementioned warning.

see : this post

Community
  • 1
  • 1
flafoux
  • 2,080
  • 1
  • 12
  • 13
  • 1
    At what point are you not plagiarising? http://stackoverflow.com/questions/11893678/warning-remote-head-refers-to-nonexistent-ref-unable-to-checkout/15631690#15631690 – random May 11 '15 at 22:03
  • @flafoux you did end your answer by saying "see: this post", however you copied the original post verbatim across many paragraphs. If you do verbatim quotes, especially of this magnitude, you need to make clear that you are quoting, not summarizing in your own words. And once you do that--by say, putting quotes around everything you wrote, it becomes clear that you essentially have a link only answer, since you have not summarized the source, so that this should not be an answer. – DWright May 12 '15 at 04:42
  • @DWright I would have mark this as duplicate but didn't found out how... If I just reply with link : people say I need to put the content, others says I don't have to, other plagia..... – flafoux May 12 '15 at 06:32
-3

remote repo can be cloned with either of the below commands

git clone https://github.com/username/repo.git
git clone git@github.com:username/repo.git

let me know the exact command your trying to help you better.