You probably know the basics of using Git, but do you know how to have a Git repo within a Git repo?
Say you already have a code project going in a folder and want to version control it in Git, here’s how you do it:
git init
git remote add origin [git URL]
git add .
git commit -m "[commit message]"
git push -u origin master
If the URL of the git repo changes (or you want to put a Personal Access Token in the Git URL):
git remote remove origin
git remote add origin [new URL]
Submodules are essentially a reference to another Git repo. You may want to break up a modular component and track it in its own repo.
By default, when you clone a git repo, it will not download the submodules.
git clone [git URL] --recursive
or --recurse-submodules
git submodule update --init --recursive
To update submodules of an existing Git clone (to point to their latest branch HEAD), do this:
git submodule update --remote --recursive
git submodule add [URL of submodule]
It’s not the same as ‘git deinit’, which doesn’t really work. You have to do 2 things:
First:
git rm [submoduleName]
Secondly, delete the module from the .git folder: .git\modules\[submoduleName]
If a submodule is giving you problems (i.e. not updating), remove it with the steps above, then git submodule add
it again.
git status
This article includes a section that covers how to make a folder in your repo into a submodule.
get yourself on the email list
comments powered by Disqus