git submodule (1)

Date: 2021/08/28 (initial publish), 2021/09/13 (last update)

Source: en/note-00026.md

Previous Post Top Next Post

TOC

The git submodule update --init is nice. I checked how all these repos are managed.

If I want to move submodule, I don’t need delete and clone again. I can simply move it with “git mv <oldpath> <newpath>” while we keep using the same local copy of repo.

Let’s see how this is done.

<modulename>/.gitmodules

This file is checked in to the parent Git repository and contains:

[submodule "pack/github/opt/ale"]
        path = pack/ale
        url = https://github.com/dense-analysis/ale.git

The checked out repo can be moved by git mv.

<modulename>/pack/ale/.git

This is created by git submodule in the submodule directory and has gitdir: ../../.git/modules/pack/github/opt/ale in it pointing to where local bare cloned repo exists. – PATH_BARE

<modulename>/.git/submodule/pack/github/opt/ale/config

This is deep in the subdirectory of the parent Git repository’s .git directory where the bare clone of submodule repository exists.

[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
        worktree = ../../../../../../pack/ale
[remote "origin"]
        url = https://github.com/dense-analysis/ale.git
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin
        merge = refs/heads/master

<modulename>/.git/config

This is in the parent Git repository’s .git and its main configuration. For submodule, this has:

[submodule "pack/github/opt/ale"]
        active = true
        url = https://github.com/dense-analysis/ale.git
Previous Post Top Next Post