2025-03-11 10:16:19 +00:00
|
|
|
Add new repo:
|
|
|
|
git submodule add https://git2.tavasi.ir/front/chat_ui.git systems/chat_ui -f
|
|
|
|
|
|
|
|
Cloning a Repository with Submodules
|
|
|
|
If you clone a repository that contains submodules, you'll need to initialize and update the submodules:
|
2025-03-11 11:39:49 +00:00
|
|
|
git clone <repository-url>
|
|
|
|
cd <repository-directory>
|
|
|
|
git submodule init
|
|
|
|
git submodule update
|
2025-03-11 10:16:19 +00:00
|
|
|
|
|
|
|
Or, you can do it in one step:
|
2025-03-11 11:39:49 +00:00
|
|
|
git clone --recurse-submodules <repository-url>
|
2025-03-11 10:16:19 +00:00
|
|
|
|
|
|
|
Updating Submodules
|
|
|
|
To update a submodule to the latest commit on its branch:
|
2025-03-11 11:39:49 +00:00
|
|
|
git submodule update --remote
|
2025-03-11 10:16:19 +00:00
|
|
|
|
2025-03-11 11:39:49 +00:00
|
|
|
## How to Remove an Existing Submodule
|
2025-03-11 10:16:19 +00:00
|
|
|
|
2025-03-11 11:39:49 +00:00
|
|
|
If the path was previously added as a submodule, you need to remove it completely before re-adding it. Follow these steps:
|
|
|
|
|
|
|
|
1. Remove the submodule entry from .gitmodules.
|
|
|
|
2. Remove the submodule from the working tree and index: git rm --cached <path-to-submodule>.
|
|
|
|
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)
|
2025-03-15 04:33:14 +00:00
|
|
|
rm -r systems/chat_ui
|
2025-03-11 11:39:49 +00:00
|
|
|
|
|
|
|
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
|