Search code examples
gitgit-submodules

Git manage submodule on branch?


I have a submodule on a development branch that isn't present on other branches. Everytime I switch branches I get a message like this:

warning: unable to rmdir master/images/development/fakeapi: Directory not empty

When I look in the directory the submodule files are still there even when I've switched to the branch with no submodule.

Is there a way to deal with this so I don't have to manually remove the submodule files after switching branches?


Solution

  • That seems to be documented in Issues with Submodules and it involves by default some manual command.

    Switching branches with submodules in them can also be tricky.
    If you create a new branch, add a submodule there, and then switch back to a branch without that submodule, you still have the submodule directory as an untracked directory

    Solution: git clean -ffd <submodule>

    If you do remove that directory and then switch back to the branch that has that submodule, you will need to run submodule update --init to repopulate it.

    You have more on those operations in "Working with Git Submodules in MantisBT"

    Is there a way to deal with this so I don't have to manually remove the submodule files after switching branches?


    Is there a way to deal with this so I don't have to manually remove the submodule files after switching branches?

    Check if git checkout -f can help