Update git submodule

This commit is contained in:
mustafa-rezae 2025-03-11 15:09:49 +03:30
parent 0f155d2f04
commit f00f10ca3d

View File

@ -3,23 +3,50 @@ git submodule add https://git2.tavasi.ir/front/chat_ui.git systems/chat_ui -f
Cloning a Repository with Submodules Cloning a Repository with Submodules
If you clone a repository that contains submodules, you'll need to initialize and update the submodules: If you clone a repository that contains submodules, you'll need to initialize and update the submodules:
git clone <repository-url> git clone <repository-url>
cd <repository-directory> cd <repository-directory>
git submodule init git submodule init
git submodule update git submodule update
Or, you can do it in one step: Or, you can do it in one step:
git clone --recurse-submodules <repository-url> git clone --recurse-submodules <repository-url>
Updating Submodules Updating Submodules
To update a submodule to the latest commit on its branch: To update a submodule to the latest commit on its branch:
git submodule update --remote git submodule update --remote
Removing a Submodule ## How to Remove an Existing Submodule
Removing a submodule is a bit more involved:
Remove the submodule entry from .gitmodules. If the path was previously added as a submodule, you need to remove it completely before re-adding it. Follow these steps:
Stage the .gitmodules changes: git add .gitmodules.
Remove the submodule from the working tree and index: git rm --cached <path-to-submodule>. 1. Remove the submodule entry from .gitmodules.
Delete the submodule directory: rm -rf <path-to-submodule>. 2. Remove the submodule from the working tree and index: git rm --cached <path-to-submodule>.
Commit the changes: git commit -m "Removed submodule <submodule-name>". 3. Delete the submodule directory: rm -rf <path-to-submodule>.
4. Stage the .gitmodules changes: git add .gitmodules.
5. Commit the changes: git commit -m "Removed submodule <submodule-name>".
errors:
# repo already exists and is not a valid git repo
Check if the path is already tracked
git ls-files --stage systems/chat_ui (100644 <hash> 0 <path>)
If it is, remove it from the index
git rm --cached systems/chat_ui
If system/chat_ui exits, remote it(chat_ui)
rm -rf systems/chat_ui
Add the submodule
git submodule add https://github.com/example/repo.git systems/chat_ui
Commit the changes
git commit -m "Added submodule at systems/chat_ui"
Verify the submodule
git submodule status
(Optional) Initialize and Update the Submodule
If the submodule was added successfully but not initialized, run:
git submodule update --init --recursive