Add-GitSubmodules is a PowerShell utility designed to simplify the process of adding and managing Git submodules within a main repository.
This module automates several tedious Git workflows, allowing you to quickly link and initialize one or more submodules in a single command. It supports both remote and local repositories, custom submodule paths, and optional push behavior.
It also includes intelligent user detection — retrieving your GitHub username automatically from Git configuration or remote URL — and interactively confirming it before proceeding.
- Automatically detects or clones the main repository if needed.
- Accepts multiple submodules at once (via array or hashtable).
- Supports custom target paths per submodule.
- Automatically initializes and updates all submodules recursively.
- Optionally skips pushing changes using the
-NoPushflag. - Verifies Git installation and ensures clean repo state.
- Confirms and stores your GitHub username for future submodule URLs.
- Make sure Git is installed and available in your system PATH.
- If the main repository URL is remote, it will be cloned automatically.
- Username detection is based on your Git config (
git config --get user.name). - You can safely re-run the command; existing submodules will be skipped.
# Import the module manually
Import-Module Add-GitSubmodules# Add a single submodule by name
Add-GitSubmodules -Main "PowershellModules" -Submodules "OhMyPoshRandomTheme"# Add multiple submodules with custom target paths
Add-GitSubmodules -Main "PowershellModules" `
-Submodules @(
@{ name = "OhMyPoshRandomTheme"; path = "modules/ohmyposh" },
@{ name = "AnotherModule"; path = "modules/tools" }
)# Prevent automatic push after adding submodules
Add-GitSubmodules -Main "PowershellModules" -Submodules "ExampleModule" -NoPushAddGitSubmodules/
├── src/
│ ├── AddGitSubmodules.psm1
│ └── AddGitSubmodules.psd1
├── examples/
│ └── ExampleProfile.ps1
├── docs/
│ └── INSTALLATION.md
├── Publish.ps1
└── README.md
OctaEDLP00 💡 GitHub: @OctaEDLP00