Skip to content

submodule

Set up a new git submodule for checkout.

This does "git submodule add" up to the fetch and checkout of the submodule contents. It preps a new submodule, creates an entry in .gitmodules and creates an empty initialized repository either at the given path in the working directory or in .git/modules with a gitlink from the working directory to the new repo.

To fully emulate "git submodule add" call this function, then open() the submodule repo and perform the clone step as needed. Lastly, call addFinalize() to wrap up adding the new submodule and .gitmodules to the index to be ready to commit.

Signature

ts
class Repository {
  submodule(
    url: string,
    path: string,
    useGitlink?: boolean | null | undefined,
  ): Submodule;
}

Parameters

  • urlrequired · string

    URL for the submodule's remote.

  • pathrequired · string

    Path at which the submodule should be created.

  • useGitlinknull | boolean

    Should workdir contain a gitlink to the repo in .git/modules vs. repo directly in workdir.

Returns

  • Submodule

    The submodule.

Released under the MIT License.