@unbare_repo
    def rename(self, new_name):
        if self.name == new_name:
            return self

        # .git/config
        pw = self.repo.config_writer()
        # As we ourselves didn't write anything about submodules into the parent .git/config, we will not require
        # it to exist, and just ignore missing entries
        if pw.has_section(sm_section(self.name)):
            pw.rename_section(sm_section(self.name), sm_section(new_name))
        # end
        pw.release()

        # .gitmodules
        cw = self.config_writer(write=True).config
        cw.rename_section(sm_section(self.name), sm_section(new_name))
        cw.release()

        self._name = new_name

        # .git/modules
        mod = self.module()
        if mod.has_separate_working_tree():
            destination_module_abspath = self._module_abspath(self.repo, self.path, new_name)
            source_dir = mod.git_dir
            # Let's be sure the submodule name is not so obviously tied to a directory
            if destination_module_abspath.startswith(mod.git_dir):
                tmp_dir = self._module_abspath(self.repo, self.path, str(uuid.uuid4()))
                os.renames(source_dir, tmp_dir)
                source_dir = tmp_dir
            # end handle self-containment
            os.renames(source_dir, destination_module_abspath)
            self._write_git_file_and_module_config(mod.working_tree_dir, destination_module_abspath)
        # end move separate git repository

        return self

    #} END edit interface

    #{ Query Interface
Rename this submodule
dataset/ETHPy150Open gitpython-developers/GitPython/git/objects/submodule/base.py/Submodule.rename