.agents/skills/git-submodule/SKILL.md
Manage Git submodules for including external repositories within a main repository. Use when working with external libraries, shared modules, or managing dependencies as separate Git repositories.
npx skillsauth add Reinasboo/Bountylab git-submoduleInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Git submodule is a feature for including other Git repositories within a main Git repository.
Key concepts:
.gitmodules fileBasic addition:
# Add submodule
git submodule add <repository-url> <path>
# Example: Add library to libs/lib path
git submodule add https://github.com/example/lib.git libs/lib
Track a specific branch:
# Add to track a specific branch
git submodule add -b main https://github.com/example/lib.git libs/lib
Commit after adding:
git add .gitmodules libs/lib
git commit -m "feat: add lib as submodule"
When cloning fresh:
# Method 1: --recursive option when cloning
git clone --recursive <repository-url>
# Method 2: Initialize after cloning
git clone <repository-url>
cd <repository>
git submodule init
git submodule update
Initialize and update in one line:
git submodule update --init --recursive
Update to latest remote version:
# Update all submodules to latest remote
git submodule update --remote
# Update a specific submodule only
git submodule update --remote libs/lib
# Update + merge
git submodule update --remote --merge
# Update + rebase
git submodule update --remote --rebase
Checkout to the referenced commit:
# Checkout submodule to the commit referenced by the main repository
git submodule update
Working inside a submodule:
# Navigate to submodule directory
cd libs/lib
# Checkout branch (exit detached HEAD)
git checkout main
# Work on changes
# ... make changes ...
# Commit and push within submodule
git add .
git commit -m "feat: update library"
git push origin main
Reflect submodule changes in main repository:
# Move to main repository
cd ..
# Update submodule reference
git add libs/lib
git commit -m "chore: update lib submodule reference"
git push
Run commands on all submodules:
# Pull in all submodules
git submodule foreach 'git pull origin main'
# Check status in all submodules
git submodule foreach 'git status'
# Checkout branch in all submodules
git submodule foreach 'git checkout main'
# Also run command on nested submodules
git submodule foreach --recursive 'git fetch origin'
Completely remove a submodule:
# 1. Deinitialize submodule
git submodule deinit <path>
# 2. Remove from Git
git rm <path>
# 3. Remove cache from .git/modules
rm -rf .git/modules/<path>
# 4. Commit changes
git commit -m "chore: remove submodule"
Example: Remove libs/lib:
git submodule deinit libs/lib
git rm libs/lib
rm -rf .git/modules/libs/lib
git commit -m "chore: remove lib submodule"
git push
Check status:
# Check submodule status
git submodule status
# Detailed status (recursive)
git submodule status --recursive
# Summary information
git submodule summary
Interpreting output:
44d7d1... libs/lib (v1.0.0) # Normal (matches referenced commit)
+44d7d1... libs/lib (v1.0.0-1-g...) # Local changes present
-44d7d1... libs/lib # Not initialized
# 1. Add submodule
git submodule add https://github.com/lodash/lodash.git vendor/lodash
# 2. Lock to a specific version (tag)
cd vendor/lodash
git checkout v4.17.21
cd ../..
# 3. Commit changes
git add .
git commit -m "feat: add lodash v4.17.21 as submodule"
# 4. Push
git push origin main
# 1. Clone the repository
git clone https://github.com/myorg/myproject.git
cd myproject
# 2. Initialize and update submodules
git submodule update --init --recursive
# 3. Check submodule status
git submodule status
# 4. Checkout submodule branch (for development)
git submodule foreach 'git checkout main || git checkout master'
# 1. Update all submodules to latest remote
git submodule update --remote --merge
# 2. Review changes
git diff --submodule
# 3. Commit changes
git add .
git commit -m "chore: update all submodules to latest"
# 4. Push
git push origin main
# In Project A
git submodule add https://github.com/myorg/shared-components.git src/shared
# In Project B
git submodule add https://github.com/myorg/shared-components.git src/shared
# When updating shared components (in each project)
git submodule update --remote src/shared
git add src/shared
git commit -m "chore: update shared-components"
# GitHub Actions
jobs:
build:
steps:
- uses: actions/checkout@v4
with:
submodules: recursive # or 'true'
# GitLab CI
variables:
GIT_SUBMODULE_STRATEGY: recursive
# Jenkins
checkout scm: [
$class: 'SubmoduleOption',
recursiveSubmodules: true
]
# Initialize all nested submodules
git submodule update --init --recursive
# Update all nested submodules
git submodule update --remote --recursive
# Edit the .gitmodules file
git config -f .gitmodules submodule.libs/lib.url https://new-url.git
# Sync local configuration
git submodule sync
# Update submodule
git submodule update --init --recursive
# 1. Back up submodule contents
cp -r libs/lib libs/lib-backup
# 2. Remove submodule
git submodule deinit libs/lib
git rm libs/lib
rm -rf .git/modules/libs/lib
# 3. Restore backup (excluding .git)
rm -rf libs/lib-backup/.git
mv libs/lib-backup libs/lib
# 4. Add as regular files
git add libs/lib
git commit -m "chore: convert submodule to regular directory"
# Add submodule with shallow clone
git submodule add --depth 1 https://github.com/large/repo.git libs/large
# Update existing submodule as shallow clone
git submodule update --init --depth 1
--recursive option in CI/CD pipelines--depth option for large repositories to save spacegit submodule status before committinggit submodule update --init is required after cloning.gitmodules can cause issues in forks.git/modules cache when removing a submodule# Force initialize
git submodule update --init --force
# Check submodule status
git submodule status
# After resolving conflict, checkout desired commit
cd libs/lib
git checkout <desired-commit>
cd ..
git add libs/lib
git commit -m "fix: resolve submodule conflict"
# Use SSH URL
git config -f .gitmodules submodule.libs/lib.url [email protected]:org/private-lib.git
git submodule sync
git submodule update --init
# Check changes within submodule
cd libs/lib
git status
git diff
# Discard changes
git checkout .
git clean -fd
# Or commit
git add .
git commit -m "fix: resolve changes"
git push
# Show submodule changes in diff
git config --global diff.submodule log
# Show submodule summary in status
git config --global status.submoduleSummary true
# Check submodule changes on push
git config --global push.recurseSubmodules check
# Also fetch submodules when fetching
git config --global fetch.recurseSubmodules on-demand
[submodule "libs/lib"]
path = libs/lib
url = https://github.com/example/lib.git
branch = main
[submodule "vendor/tool"]
path = vendor/tool
url = [email protected]:example/tool.git
shallow = true
development
Security code review for vulnerabilities. Use when asked to "security review", "find vulnerabilities", "check for security issues", "audit security", "OWASP review", or review code for injection, XSS, authentication, authorization, cryptography issues. Provides systematic review with confidence-based reporting.
development
Implement security best practices for web applications and infrastructure. Use when securing APIs, preventing common vulnerabilities, or implementing security policies. Handles HTTPS, CORS, XSS, SQL Injection, CSRF, rate limiting, and OWASP Top 10.
development
Create responsive web designs that work across all devices and screen sizes. Use when building mobile-first layouts, implementing breakpoints, or optimizing for different viewports. Handles CSS Grid, Flexbox, media queries, viewport units, and responsive images.
content-media
Produce programmable videos with Remotion using scene planning, asset orchestration, and validation gates for automated, brand-consistent video content.