| name | git-merge-main |
| description | Use when merging the main branch into the current feature branch to pick up upstream changes. |
| triggers | ["git merge main","merge main","update from main","sync with main","get latest main"] |
| version | 1.0.0 |
| user_invocable | true |
Scope Constraints
- Write operation — creates merge commits in the local repository
- Fetches from remote to update the target branch before merging
- Does not push to remote — use push skill for that
- Does not resolve conflicts — use conflicts skill if merge produces conflicts
Input Sanitization
- Target branch name: only alphanumeric characters, hyphens, underscores, and forward slashes. Reject spaces,
.., shell metacharacters, or null bytes.
- Flags: only
--no-commit accepted. Reject arbitrary strings.
/git-merge-main - Merge Main Into Feature Branch
Merge the latest main branch into your current feature branch to get updates.
Usage
/git-merge-main
/git-merge-main develop
/git-merge-main --no-commit
When to Use
- Your feature branch is behind main
- You need changes from main to continue your work
- Before creating a PR (to ensure no conflicts)
- When main has critical fixes you need
Workflow
Step 1: Pre-flight Checks
CURRENT=$(git branch --show-current)
if [ "$CURRENT" = "main" ] || [ "$CURRENT" = "master" ]; then
echo "Already on main branch. Nothing to merge."
echo "Did you mean /git-pull?"
exit 1
fi
if ! git diff --quiet || ! git diff --cached --quiet; then
echo "You have uncommitted changes."
echo "Options:"
echo " /git-stash - Stash changes first"
echo " /commit - Commit changes first"
exit 1
fi
Step 2: Update Main
git fetch origin main:main 2>/dev/null || git fetch origin main
echo "Commits from main to be merged:"
git log --oneline HEAD..origin/main | head -20
Step 3: Check for Potential Conflicts
if ! git merge --no-commit --no-ff origin/main 2>/dev/null; then
echo "Merge will have conflicts."
git merge --abort
git diff --name-only --diff-filter=U
fi
Step 4: Execute Merge
git merge origin/main --no-ff -m "Merge main into $CURRENT"
git merge origin/main --no-commit --no-ff
Step 5: Report Result
Show merge result and any follow-up needed.
Output Format
Clean Merge
Merging main into feat/dark-mode...
Merged 5 commits from main:
abc1234 Fix security vulnerability
def5678 Update dependencies
ghi9012 Improve performance
jkl3456 Add new API endpoint
mno7890 Documentation updates
Files updated:
package.json
src/api/endpoints.ts
src/utils/security.ts
README.md
Merge complete! Your branch now includes all changes from main.
Next steps:
- Test your feature still works
- /git-push to update remote branch
Already Up To Date
Branch feat/dark-mode is already up to date with main.
No merge needed.
Merge Conflicts
Merge conflicts detected!
Conflicting files:
- src/components/Header.tsx (both modified)
- src/styles/theme.css (both modified)
To resolve:
/git-conflicts # Get help resolving
After resolving:
git add <resolved-files>
git commit
To abort:
/git-abort
No-Commit Preview
When using --no-commit:
Merge staged but not committed.
Changes from main:
M src/api/endpoints.ts
M package.json
A src/utils/newHelper.ts
Review the changes, then:
git commit -m "Merge main into feat/dark-mode"
Or abort:
git merge --abort
Best Practices
- Always fetch first: Ensures you have the latest main
- Check status before: No uncommitted changes
- Test after merge: Ensure your feature still works
- Commit message: Use descriptive merge message
- Consider rebase: For cleaner history, use
/git-rebase instead
Merge vs Rebase
| Merge | Rebase |
|---|
| Preserves complete history | Creates linear history |
| Shows when integration happened | Looks like sequential development |
| Better for shared branches | Better for personal branches |
| Non-destructive | Rewrites commit history |
Integration
- Use
/git-sync first to see what's on main
- Use
/git-rebase for cleaner history (alternative)
- Use
/git-conflicts if merge has conflicts
- Use
/git-abort to cancel a failed merge