"You are on a branch yet to be born" when adding git submodule

GitGit Submodules

Git Problem Overview


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.

Git Solutions


Solution 1 - Git

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.

Solution 2 - Git

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>

Solution 3 - Git

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.

Solution 4 - Git

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionmatt bView Question on Stackoverflow
Solution 1 - GitlisachenkoView Answer on Stackoverflow
Solution 2 - Gitk4narView Answer on Stackoverflow
Solution 3 - GitUselessView Answer on Stackoverflow
Solution 4 - GitJohn McFarlaneView Answer on Stackoverflow