Reputation: 2537
I want to add a submodule on a freshly created git repository and I get an error. If I execute the same command again it succeeds.
C:\>mkdir MyRepo
C:\>cd MyRepo
C:\MyRepo>git init
Initialized empty Git repository in C:/MyRepo/.git/
C:\MyRepo>git submodule add -b refs/heads/master C:\MySubmodulesLibrary\MySubmodule MySubmodule
Cloning into 'C:/MyRepo/MySubmodule'...
done.
fatal: 'origin/refs/heads/master' is not a commit and a branch 'refs/heads/master' cannot be created from it
Unable to checkout submodule 'MySubmodule'
C:\MyRepo>git submodule add -b refs/heads/master C:\MySubmodulesLibrary\MySubmodule MySubmodule
Adding existing repo at 'MySubmodule' to the index
warning: LF will be replaced by CRLF in .gitmodules.
The file will have its original line endings in your working directory.
Git version: 2.17.1.windows.1
I'd like to know what am I doing wrong and what can I do to make this operation succeed the first time I execute it.
*This question comes as a follow up of a Git Extensions bug where the first time you try to add a submodule it fails but the second time it succeeds. These are the commands issued by Git Extensions when adding a submodule; however, the same behavior occurs when issuing them from the command line. I don't know if this behavior is expected from Git (and the problem is with Git Extensions issuing the wrong commands) or this is a Git bug.
Upvotes: 0
Views: 2067
Reputation: 3201
Try to use
git submodule add -b master C:\MySubmodulesLibrary\MySubmodule MySubmodule
-b
is the simple branch name.
Upvotes: 2