132

I am attempting to add a few submodules to my .vim/bundles directory, and when I attempt to add this particular repo Git gives me a strange error I've never seen before:

$ git submodule add -f git://github.com/derekwyatt/vim-scala.git .vim/bundle/vim-scala
fatal: You are on a branch yet to be born
Unable to checkout submodule '.vim/bundle/vim-scala'

Any idea what can cause this?

If I clone the same repo to a test directory (not through the submodule command), it works fine, and creates the expected files.

4 Answers 4

232

To fix that error, you should delete the folder with the same path to the submodule inside .git/modules/ directory. This error can occurs when url was incorrect for submodule for the first-time when submodule was added.

9
  • 2
    Thanks, that did the trick. Was a bit non-obvious at first that since I was cloning to .vim/bundle/vim-scala the path to delete was .git/modules/.vim/bundle/vim-scala
    – matt b
    Aug 22, 2012 at 14:17
  • 2
    If you're on windows note that the directory under .git/modules may not show up unless you dir /AH
    – oz10
    Sep 15, 2012 at 22:47
  • 13
    After I see delete that .git/modules/path/to/submodule directory and try to re-add the submodule, I receive the error The following path is ignored by one of your .gitignore files: path/to/submodule. Sep 18, 2012 at 15:46
  • 1
    @Drew Noakes remove .vim/bundle/vim-scala created after first run of git submodule add Feb 20, 2013 at 14:01
  • 1
    This, together with Useless' answer solved my problem. An ideal answer would be a combination of both. Thanks! Jun 2, 2017 at 15:32
21

This error can happen if you are adding a submodule which doesn't have a master branch. If you want to use another branch when adding the submodule (develop for instance), you can use the following command:

git submodule add -b <branch> <repository>
2
  • 1
    In my case repo was newly created and therefore didn't have any files and branches (was empty), so git submodule add -b master <repo.git> <folder> helped
    – vladkras
    Nov 17, 2016 at 15:24
  • This was my problem my submodule had only 2 branches none of them is a master your solution worked for me.
    – Guerneen4
    Mar 16, 2017 at 14:10
13

You need to add a submodule inside an existing repo, that repo needs to be in a state to add & commit the submodule link, and the submodule repo itself must have a commit to check out.

Now, the submodule repo itself must be ok if you can create a regular clone elsewhere. However, it looks like submodule add complains if the repo is empty while clone does not. This guy suggests this is fixable by just running the same submodule add command again.

If the inner repo is not empty, check the repo you want to contain the submodule. Change to the same directory where you ran git submodule add, and run git status, and git branch to verify that your containing repo has at least one branch created and isn't in a weird state.

6
  • I've verified all of these things. When I check out the desired repo to another directory, it has many files, and a master branch. The repo I am trying to add this one to as a submodule is on the master branch, has no obvious problems (status returns some modified files, but that's all), and weirdest of all is that I can add other submodules just fine to this repository.
    – matt b
    Aug 9, 2012 at 17:48
  • Also odd: after the fatal warning from my OP, git leaves an empty dir at .vim/bundle/vim-scala. I also noticed that even though .gitmodules is untouched, it added some lines referring to this github.com repo to .git/config, but after removing those I still get the same fatal error message.
    – matt b
    Aug 9, 2012 at 17:49
  • 7
    +1 Argh! This guy suggests this is fixable by just running the same submodule add command again.. I've been battling this problem trying to find a sensible answer and this finally fixed it. This was for git 1.8.0 under MSYS while creating a submodule from BitBucket, so if you're in the same situation, try this first. Dec 28, 2012 at 6:10
  • Adding twice worked for me, too. But I don't understand why. Any explanation?
    – Elliot
    Mar 1, 2018 at 5:04
  • Adding twice here as well. I would love to understand why though Aug 5, 2019 at 12:07
0

As alluded to by @drew-noakes, this can be caused by attempting to add a submodule using a directory name that is listed in your .gitignore file.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.