3

I'm using git 1.8.4 and trying to add a submodule that tracks master of another repository. I tried adding it as follows:

git submodule add -b master /path/to/myrepo.git

And I get the following error when I try to add it

Cloning into 'myrepo.git'...
warning: You appear to have cloned an empty repository.
done.
fatal: Cannot update paths and switch to branch 'master' at the same time.
Did you intend to checkout 'origin/master' which can not be resolved as commit?
Unable to checkout submodule 'myrepo'

I'm not sure what this means...can someone explain?

Jeff Storey
  • 56,312
  • 72
  • 233
  • 406
  • Can you try to go within that submodule, do a `git checkout -b master origin/master`, go back one level, and `git submodule update --remote --init`? – VonC Sep 20 '13 at 06:03
  • I get the same message message saying the following when I try the first checkout command fatal: Cannot update paths and switch to branch 'master' at the same time. Did you intend to checkout 'origin/master' which can not be resolved as commit? – Jeff Storey Sep 25 '13 at 14:16
  • Then try, in the submodule: `git branch -b master ; git reset --hard origin/master` (as in http://stackoverflow.com/a/17137740/6309). but if it still complains about `origin/master`, then the remote for that submodule might no be correct. What `git remote -v` returns? Is there a master branch in the actual repo `/path/to/myrepo.git`? – VonC Sep 25 '13 at 14:26
  • I verified the actual repo has a master branch. When I run `git remote -v` in the submodule directory I get `origin /path/to/sub/module.git/ (fetch)` `origin /path/to/sub/module.git/ (push)` but still getting the same errors about origin master – Jeff Storey Sep 25 '13 at 15:03
  • What `git branch -avvv` return (in the submodule)? Do you see an `origin/master` in the list of branches? – VonC Sep 25 '13 at 15:17
  • If I go into the submodule folder from within the parent project and run that command,I do not. If I checkout the submodule to its own project, then I do. – Jeff Storey Sep 25 '13 at 15:24
  • Ok. ONe way to move forward would be to start from a fresh clone of the parent repo (without any reference to your submodule), and repeat the steps: `git submodule add -b master /path/to/myrepo.git ; git submodule update --remote --init`. – VonC Sep 25 '13 at 15:27
  • Ok, thanks. I'll give that a try. Probably won't be able to get to it for a little bit, but I'll post back with the results. I appreciate your help. – Jeff Storey Sep 25 '13 at 15:28
  • @VonC Sorry it's taken me so long to get back to you. You were correct that something was messed up with my repository configuration. All works now. If you post your suggestions as an answer, I will accept it. – Jeff Storey Oct 08 '13 at 03:07

1 Answers1

2

The fact that the submodule doesn't appear to have a branch (ie: "cd submodule ; git branch -avvv" doesn't return anything, means the submodule configuration in the parent repo isn't properly initialized and updated.

I commented:

One way to move forward would be to start from a fresh clone of the parent repo (without any reference to your submodule), and repeat the steps:

git submodule add -b master /path/to/myrepo.git ; 
git submodule update --remote --init. –
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250