# GIT SUBMODULE working
How to add git-submodule?
go to git-initialized directory, and write the following command:
```
git submodule add <ssh-git repo address> <directory where the submodule should be added>
```
Example:
```
git submodule add git@github.com:octobotics/octo_arm_teleop.git src/octo_arm_teleop
```
How to pull git repo with all submodule?
Use the following command:
```
git clone --recurse-submodule <address>
```
if you forgot to use above command and simply clone the repo, then following commnand will pull all git submodules.
go to directory and use the command:
```
git submodule update --init --recursive
```
How to update git-submodule?
Some Points:
* main repository will be linked to the commit of submodule pkg.
* if we update the submodule pkg, still main repo will have old commit of the submodule pkg. It will not update the main repository.
* while commiting in submodule if an **"detached head error "** shows, just git checkout to main branch.
There are two scenarios:
Scenario-1
* assume that you have **New_year** repository in which you have submoduled package **K**.
* In order to update submodule pkg **K** and reflect the changes in **New_year** repository, following steps will help.
* make changes inside pkg **K**.
* commit and push the changes (from inside the **K** pkg directory.)
* go to **New_year** directory and commit (and push) the changes of pkg **K**.
* In this way, the latest changes of pkg **K** will reflect in **New_year** repository. and when someone pull the repository the new changes will be reflected.
Scenario-2
* assume that you have **New_year** repository in which you have submoduled package **K**.
* also at some **F** location you have package **K** stored.
* if we make changes in package **K** at location **F** and commmit and push it.
* In order to reflect those changes in **New_year** repo, following steps will help:
* got to the pkg **K** location inside **New_year** repo.
* pull the repository **K**.
* go to main directory of **New_year** dir.
* commit and push the changes.
* this will update the commit of submodule.