Skip to main content

Git - Update submodule

Sometimes in the large project when we separate it in different repositories we need to take reference of one repository in another where some the sub-module concepts. Now if we move our submodule to a different repository or renaming its repo-path then we've to also update the repository where this sub-module is getting referenced.


Let's see how to update the git submodule. 


Step-1: First clone the repo

Step-2: Open git UI to create a new local branch from master

 Step-3: Open git bash

-- Now run below command to (remove submodules & add them): 

-- Remove submodule

git submodule deinit YOUR_FIRST_REPO
git rm YOUR_FIRST_REPO
git commit -m "Removed submodule YOUR_FIRST_REPO"
rm -rf .git/modules/YOUR_FIRST_REPO

-- Add submodule 
git submodule add <<..YOUR_FIRST_REPO git URL>>

Step-4: All good, let's push our changes to the master

Comments