| name | git-pr-helper |
| description | Git workflow assistant for pull request creation, branch management, and merge coordination. Use when creating PRs, merging branches, resolving conflicts, or cleaning up session branches. Provides intelligent PR descriptions, safety checks, and workflow guidance. |
| allowed-tools | ["Bash","Read","Write","Edit","Glob","Grep"] |
Git PR Helper
Expert at managing git workflows for pull requests, merges, and branch management with a focus on safety, quality, and best practices.
Core Mission
Assist with pull request creation, branch management, merge coordination, and conflict resolution while ensuring code quality and preventing data loss.
When to Use This Skill
Use this skill when:
- Creating a pull request from a feature branch
- Merging branches (feature → main/master)
- Resolving merge conflicts
- Cleaning up old session or feature branches
- Generating PR descriptions from commits
- Checking if work is ready to merge
- Recovering from git mistakes
Do NOT use this skill for:
- Preventing file deletion (use git hooks + CLAUDE.md instead)
- Creating session branches at workflow start (use CLAUDE.md guidance)
- Enforcing branch policies (use git hooks instead)
Skill Capabilities
1. Pull Request Creation
Purpose: Create high-quality pull requests with comprehensive descriptions
Create PR with Generated Description
To create a PR:
-
Verify we're on a feature branch:
CURRENT_BRANCH=$(git branch --show-current)
if [ "$CURRENT_BRANCH" = "main" ] || [ "$CURRENT_BRANCH" = "master" ]; then
echo "❌ ERROR: Cannot create PR from main/master branch"
exit 1
fi
echo "✓ Current branch: $CURRENT_BRANCH"
-
Check git status is clean:
if [ -n "$(git status --porcelain)" ]; then
echo "⚠️ WARNING: Uncommitted changes detected"
git status --short
echo ""
echo "Commit these changes before creating PR? (y/n)"
else
echo "✓ Working tree clean"
fi
-
Determine base branch:
BASE_BRANCH=$(git remote show origin 2>/dev/null | grep 'HEAD branch' | cut -d' ' -f5)
if [ -z "$BASE_BRANCH" ]; then
if git show-ref --verify --quiet refs/heads/main; then
BASE_BRANCH="main"
elif git show-ref --verify --quiet refs/heads/master; then
BASE_BRANCH="master"
else
echo "⚠️ Cannot detect base branch. Please specify manually."
fi
fi
echo "Base branch: $BASE_BRANCH"
-
Get all commits on this branch:
git log $BASE_BRANCH..HEAD --oneline
git log $BASE_BRANCH..HEAD --format="%h %s%n%b" --reverse
-
Get diff summary:
git diff $BASE_BRANCH...HEAD --stat
git diff $BASE_BRANCH...HEAD --name-only
-
Generate PR description:
Analyze commits and changes to create:
## Summary
- [Brief bullet points of main changes]
- [Focus on WHY, not WHAT]
- [User-facing impact]
## Changes Made
- [Detailed technical changes]
- [Components affected]
- [API changes if applicable]
## Testing
- [ ] Unit tests added/updated
- [ ] Manual testing completed
- [ ] Edge cases considered
- [ ] Documentation updated
## Related Issues
Closes #[issue-number] (if applicable)
## Notes for Reviewers
[Any context reviewers should know]
[Areas needing special attention]
-
Check if remote tracking branch exists:
if git rev-parse --verify --quiet origin/$CURRENT_BRANCH >/dev/null 2>&1; then
echo "✓ Remote branch exists"
else
echo "⚠️ Remote branch does not exist. Need to push first."
echo "Push now? (y/n)"
fi
-
Create PR using GitHub CLI:
gh pr create \
--title "[Generated title from commits]" \
--body "$(cat <<'EOF'
[Generated PR description]
EOF
)" \
--base "$BASE_BRANCH" \
--head "$CURRENT_BRANCH"
-
Update CLAUDE-activeContext.md (if exists):
if [ -f CLAUDE-activeContext.md ]; then
PR_URL=$(gh pr view --json url -q .url)
echo "PR created: $PR_URL" >> CLAUDE-activeContext.md
fi
Generate PR Description Only
To generate a PR description without creating the PR:
- Follow steps 1-6 above
- Output the generated description for user review
- Ask if user wants to create PR with this description
2. Merge Coordination
Purpose: Safely merge branches with conflict detection and resolution guidance
Check Merge Readiness
To check if branch is ready to merge:
echo "=== MERGE READINESS CHECK ==="
echo ""
CURRENT_BRANCH=$(git branch --show-current)
BASE_BRANCH=${BASE_BRANCH:-main}
if [ "$CURRENT_BRANCH" = "$BASE_BRANCH" ]; then
echo "❌ ERROR: Already on base branch $BASE_BRANCH"
exit 1
fi
echo "✓ Feature branch: $CURRENT_BRANCH"
echo ""
if [ -n "$(git status --porcelain)" ]; then
echo "❌ Uncommitted changes detected:"
git status --short
echo ""
else
echo "✓ Working tree clean"
echo ""
fi
echo "Fetching latest from remote..."
git fetch origin $BASE_BRANCH
echo ""
BEHIND=$(git rev-list --count HEAD..origin/$BASE_BRANCH)
if [ "$BEHIND" -gt 0 ]; then
echo "⚠️ Base branch has $BEHIND new commits"
echo "Consider rebasing: git rebase origin/$BASE_BRANCH"
else
echo "✓ Up to date with base branch"
fi
echo ""
echo "Checking for potential conflicts..."
git merge-tree $(git merge-base HEAD origin/$BASE_BRANCH) HEAD origin/$BASE_BRANCH > /tmp/merge-preview.txt
if grep -q "changed in both" /tmp/merge-preview.txt; then
echo "⚠️ CONFLICTS DETECTED:"
grep -A 3 "changed in both" /tmp/merge-preview.txt
echo ""
else
echo "✓ No conflicts detected"
echo ""
fi
if [ -f package.json ] && grep -q "\"test\"" package.json; then
echo "Running tests..."
npm test
elif [ -f pytest.ini ] || [ -d tests ]; then
echo "Running tests..."
pytest
elif [ -f Cargo.toml ]; then
echo "Running tests..."
cargo test
else
echo "ℹ️ No test command found (skipped)"
fi
echo ""
if command -v gh &> /dev/null; then
echo "Checking CI status..."
gh pr checks 2>/dev/null || echo "ℹ️ No PR found or CI configured"
fi
echo ""
echo "=== READINESS CHECK COMPLETE ==="
Merge Branch Safely
To merge a feature branch:
-
Run merge readiness check (above)
-
Ask user for merge strategy:
- Regular merge (preserves all commits)
- Squash merge (single commit)
- Rebase and merge (linear history)
-
For regular merge:
git checkout $BASE_BRANCH
git merge --no-ff $FEATURE_BRANCH -m "Merge branch '$FEATURE_BRANCH'"
-
For squash merge:
git checkout $BASE_BRANCH
git merge --squash $FEATURE_BRANCH
git log $BASE_BRANCH..$FEATURE_BRANCH --format="%s" > /tmp/commit-msg.txt
git commit -m "$(cat <<'EOF'
[Squashed commit title]
Changes included:
$(cat /tmp/commit-msg.txt)
EOF
)"
-
For rebase and merge:
git checkout $FEATURE_BRANCH
git rebase $BASE_BRANCH
git checkout $BASE_BRANCH
git merge --ff-only $FEATURE_BRANCH
-
Push to remote:
git push origin $BASE_BRANCH
-
Clean up feature branch (optional):
git branch -d $FEATURE_BRANCH
git push origin --delete $FEATURE_BRANCH
3. Conflict Resolution
Purpose: Guide through merge conflict resolution
Detect and Analyze Conflicts
When conflicts occur:
-
Show conflicted files:
git status | grep "both modified"
-
For each conflicted file, show conflict markers:
grep -n "<<<<<<< HEAD" $CONFLICTED_FILE
-
Explain the conflict:
<<<<<<< HEAD = Your current branch changes
======= = Separator
>>>>>>> branch-name = Incoming branch changes
-
Provide resolution strategies:
- Accept current changes (ours):
git checkout --ours $FILE
- Accept incoming changes (theirs):
git checkout --theirs $FILE
- Manually resolve: Edit file to keep both/choose wisely
-
After resolution:
git add $RESOLVED_FILE
git status
git merge --continue
Abort Problematic Merge
If merge goes wrong:
git merge --abort
git rebase --abort
git status
4. Branch Cleanup
Purpose: Safely remove old session/feature branches
List Branches for Cleanup
To identify branches that can be cleaned up:
echo "=== BRANCH CLEANUP ANALYSIS ==="
echo ""
CURRENT_BRANCH=$(git branch --show-current)
BASE_BRANCH=${BASE_BRANCH:-main}
echo "Local branches:"
git branch -vv
echo ""
echo "Merged branches (safe to delete):"
git branch --merged $BASE_BRANCH | grep -v "^\*" | grep -v "$BASE_BRANCH"
echo ""
echo "Unmerged branches (verify before deleting):"
git branch --no-merged $BASE_BRANCH | grep -v "^\*"
echo ""
echo "Branch activity (last commit date):"
for branch in $(git branch | sed 's/^\*/ /'); do
printf "%-30s %s\n" "$branch" "$(git log -1 --format=%cd --date=relative $branch)"
done
Clean Up Merged Branches
To delete merged branches:
MERGED_BRANCHES=$(git branch --merged $BASE_BRANCH | grep -v "^\*" | grep -v "$BASE_BRANCH" | grep -v "main" | grep -v "master")
if [ -z "$MERGED_BRANCHES" ]; then
echo "No merged branches to clean up"
else
echo "The following merged branches will be deleted:"
echo "$MERGED_BRANCHES"
echo ""
echo "Proceed? (requires user confirmation)"
echo "$MERGED_BRANCHES" | xargs git branch -d
echo "✓ Local merged branches deleted"
echo ""
echo "Delete remote branches too? (requires user confirmation)"
echo "$MERGED_BRANCHES" | xargs -I {} git push origin --delete {}
fi
Clean Up Session Branches
To clean up old session branches specifically:
SESSION_BRANCHES=$(git branch | grep "session/" | sed 's/^\*/ /' | xargs)
if [ -z "$SESSION_BRANCHES" ]; then
echo "No session branches found"
else
echo "Session branches:"
for branch in $SESSION_BRANCHES; do
MERGED=$(git branch --merged $BASE_BRANCH | grep -q "$branch" && echo "✓ merged" || echo "✗ unmerged")
LAST_COMMIT=$(git log -1 --format="%cd" --date=relative $branch)
printf "%-40s %-12s %s\n" "$branch" "$MERGED" "$LAST_COMMIT"
done
echo ""
echo "Delete merged session branches? (y/n)"
fi
5. PR Review Assistance
Purpose: Help review PRs and provide feedback
Analyze PR Changes
To review a PR:
PR_NUMBER=${1:-$(gh pr view --json number -q .number 2>/dev/null)}
if [ -z "$PR_NUMBER" ]; then
echo "No PR found. Specify PR number or create a PR first."
exit 1
fi
gh pr view $PR_NUMBER
gh pr diff $PR_NUMBER
gh pr diff $PR_NUMBER --name-only
gh pr checks $PR_NUMBER