diff --git a/GIT_SUBMODULE.md b/GIT_SUBMODULE.md index f3a9e57..8f64f5d 100644 --- a/GIT_SUBMODULE.md +++ b/GIT_SUBMODULE.md @@ -3,23 +3,50 @@ 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: - git clone - cd - git submodule init - git submodule update +git clone +cd +git submodule init +git submodule update Or, you can do it in one step: - git clone --recurse-submodules +git clone --recurse-submodules Updating Submodules To update a submodule to the latest commit on its branch: - git submodule update --remote +git submodule update --remote -Removing a Submodule -Removing a submodule is a bit more involved: +## How to Remove an Existing Submodule - Remove the submodule entry from .gitmodules. - Stage the .gitmodules changes: git add .gitmodules. - Remove the submodule from the working tree and index: git rm --cached . - Delete the submodule directory: rm -rf . - Commit the changes: git commit -m "Removed submodule ". +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 . +3. Delete the submodule directory: rm -rf . +4. Stage the .gitmodules changes: git add .gitmodules. +5. Commit the changes: git commit -m "Removed submodule ". + +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 0 ) + +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