automation
Automate Git Submodule Addition with Bash Script
A Bash script to automate adding Git submodules, including branch creation and pull request generation using GitHub CLI.
Shipped January 2026
A Bash script that automates adding Git submodules to a repository. It handles branch creation, submodule addition, commit, push, and pull request creation via the GitHub CLI.
Features
- Adds a Git submodule to a specified directory within your repository.
- Automatically creates a new branch named after the submodule repository.
- Commits and pushes changes to GitHub.
- Creates a pull request using the GitHub CLI (
gh).
Tech Stack
- Shell scripting (Bash)
- Git
- GitHub CLI (
gh)
Getting Started
Prerequisites
- Git installed and configured on your system.
- GitHub CLI (
gh) installed and authenticated. Installation instructions: GitHub CLI Installation.
Installation & Usage
-
Clone or download this repository.
-
Make the script executable:
chmod +x add_submodule.sh
- Run the script with the submodule repository link and the target location within your repository:
./add_submodule.sh <submodule-link> <location>
Example:
./add_submodule.sh https://github.com/username/repo.git content/posts
This command adds the submodule repo into the content/posts/repo directory, creates a new branch named repo, commits the changes, pushes the branch, and opens a pull request against the main branch.
Project Structure
add-submodule-script/
├── add_submodule.sh # Main Bash script to add submodules
├── README.md # This README file
└── index.md # Tutorial/blog post explaining the script
Future Work / Roadmap
- Support customizing the base branch for pull requests.
- Add error handling for GitHub CLI failures.
- Support adding multiple submodules in a single run.
- Add options for customizing commit messages and pull request descriptions.
- Provide more detailed logging and a verbose mode.
Note: This script assumes you have Git and GitHub CLI configured and authenticated.
Need more context?
Want help adapting this playbook?
Send me the constraints and I'll annotate the relevant docs, share risks I see, and outline the first sprint so the work keeps moving.