简体   繁体   中英

Git submodule add error

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.

Try to use

git submodule add -b master C:\MySubmodulesLibrary\MySubmodule MySubmodule

-b is the simple branch name.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM