Git (cmd line)

You probably know the basics of using Git, but do you know how to have a Git repo within a Git repo?

Basic: Initiate a Git repo from a folder with existing files

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]

Git (with submodules)

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.

Clone a git repo with submodules

git clone [git URL] --recursive or --recurse-submodules

Grab submodule of an existing Git clone (which did not include 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

Add a submodule

git submodule add [URL of submodule]

Remove a 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.

Other useful commands

git status

More Reading

This article includes a section that covers how to make a folder in your repo into a submodule.

https://github.blog/2016-02-01-working-with-submodules/

get yourself on the email list

//Powered by MailChimp - low volume, no spam

comments powered by Disqus