Thursday, March 31, 2011

Using git to add a submodule

The command to add a submodule to a project is:
git submodule add <URL of the submodule repo> <path to place submodule> 
Example:
git submodule add git@1.1.1.1:Submodule.git ./Submodule 
This will modify the .gitmodules file in the repository. When I ran this command, I got a fatal message stating:
fatal: LF would be replaced by CRLF in .gitmodules
Failed to register submodule 'Submodule' 
Modifying the .gitmodules file manually by replacing the LF with a CRLF fixed this problem (ie. open the file in Notepad++ or another text editor, delete the end of line character, and hit 'Enter' on the keyboard for each of the new lines added for this submodule).

Running the command
git submodule status
will show that this submodule isn't ready to be used as of yet. Run
git submodule init
to initialize this submodule. You should not need to run update for this submodule because the clone happened when the submodule was added.

Add, commit, and push this file so that other users will be able to have the changes.

No comments:

Post a Comment