Bobby2067

git-workflow

0
0
# Install this skill:
npx skills add Bobby2067/agent-skills-collection --skill "git-workflow"

Install specific skill from multi-skill repository

# Description

Comprehensive Git workflow management including branching strategies, commit conventions, merge conflict resolution, and repository maintenance. Use when users need help with Git operations, version control workflows, branch management, commit history organization, or collaborative development practices.

# SKILL.md


name: git-workflow
description: Comprehensive Git workflow management including branching strategies, commit conventions, merge conflict resolution, and repository maintenance. Use when users need help with Git operations, version control workflows, branch management, commit history organization, or collaborative development practices.


Git Workflow

Overview

This skill provides Git best practices, workflows, and automation scripts for efficient version control management, from basic operations to advanced collaborative workflows.

Quick Reference

Essential Commands

# Check status
git status

# Stage changes
git add .                   # Stage all changes
git add -p                  # Interactive staging

# Commit
git commit -m "message"     # Direct commit
git commit                  # Opens editor for detailed message
git commit --amend         # Modify last commit

# Branches
git branch                  # List branches
git checkout -b feature-x   # Create and switch to new branch
git merge feature-x         # Merge branch
git rebase main            # Rebase current branch on main

# Remote
git fetch                   # Download remote changes
git pull                    # Fetch and merge
git push                    # Push changes
git push -u origin branch   # Set upstream and push

Branching Strategies

Git Flow

Best for release-based development:
- main - Production-ready code
- develop - Integration branch
- feature/* - Feature branches
- release/* - Release preparation
- hotfix/* - Emergency fixes

GitHub Flow

Best for continuous deployment:
- main - Always deployable
- feature-branches - Short-lived feature branches
- Pull requests for code review
- Deploy from main

GitLab Flow

Best for environments with staging:
- main - Latest code
- production - Production deployment
- staging - Staging environment
- Environment branches for different stages

Commit Conventions

Conventional Commits

Format: <type>(<scope>): <subject>

Types:
- feat: New feature
- fix: Bug fix
- docs: Documentation changes
- style: Code style changes
- refactor: Code refactoring
- test: Test additions/changes
- chore: Build/tooling changes

Examples:

git commit -m "feat(auth): add OAuth2 integration"
git commit -m "fix(api): handle null response in user endpoint"
git commit -m "docs(readme): update installation instructions"

Commit Message Template

<type>(<scope>): <subject>

<body>
- Explain what and why, not how
- Use bullet points for multiple changes
- Reference issues/tickets

<footer>
Closes #123
Co-authored-by: Name <email>

Merge Conflict Resolution

Strategy

  1. Update main branch
  2. Merge or rebase feature branch
  3. Resolve conflicts
  4. Test thoroughly
  5. Complete merge

Commands

# Start merge
git merge feature-branch

# During conflict resolution
git status                  # See conflicted files
git diff                     # View conflicts
git add resolved-file.txt    # Mark as resolved
git merge --continue         # Continue merge

# Or abort
git merge --abort            # Cancel merge

Conflict Markers

<<<<<<< HEAD
Current branch content
=======
Incoming branch content
>>>>>>> feature-branch

Advanced Operations

Interactive Rebase

Clean up commit history:

git rebase -i HEAD~3        # Interactive rebase last 3 commits

# Commands in interactive mode:
# pick - use commit
# reword - change message
# edit - stop for amending
# squash - combine with previous
# fixup - combine, discard message
# drop - remove commit

Cherry-Pick

Apply specific commits:

git cherry-pick abc123      # Apply single commit
git cherry-pick abc123..xyz789  # Apply range

Stashing

Temporary storage:

git stash                   # Save current changes
git stash pop               # Apply and remove stash
git stash list              # List all stashes
git stash apply stash@{0}   # Apply specific stash
git stash drop              # Remove stash

Bisect

Find problematic commits:

git bisect start
git bisect bad              # Current commit is bad
git bisect good abc123      # Known good commit
# Test each commit git gives you
git bisect good/bad         # Mark as good or bad
git bisect reset            # End bisect session

Repository Maintenance

Cleanup Commands

# Remove untracked files
git clean -fd               # Files and directories
git clean -fdx              # Including ignored files

# Garbage collection
git gc                      # Clean up repository
git gc --aggressive         # Thorough cleanup

# Prune remote branches
git remote prune origin     # Remove deleted remote branches
git fetch --prune           # Fetch and prune

History Rewriting

# Change author for last commit
git commit --amend --author="Name <email>"

# Change multiple commits
git rebase -i HEAD~n
# Mark commits as 'edit'
git commit --amend --author="Name <email>"
git rebase --continue

Hooks and Automation

Pre-commit Hook Example

.git/hooks/pre-commit:

#!/bin/sh
# Run tests before commit
npm test
if [ $? -ne 0 ]; then
    echo "Tests failed. Commit aborted."
    exit 1
fi

Commit Message Hook

.git/hooks/commit-msg:

#!/bin/sh
# Enforce conventional commits
commit_regex='^(feat|fix|docs|style|refactor|test|chore)(\(.+\))?: .+'
if ! grep -qE "$commit_regex" "$1"; then
    echo "Invalid commit message format!"
    exit 1
fi

Troubleshooting

Common Issues

# Undo last commit (keep changes)
git reset --soft HEAD~1

# Undo last commit (discard changes)
git reset --hard HEAD~1

# Recover deleted branch
git reflog
git checkout -b recovered-branch abc123

# Fix wrong branch commits
git cherry-pick commit-hash  # On correct branch
git reset --hard HEAD~n      # On wrong branch

Resources

scripts/

  • git-flow-init.sh - Initialize Git Flow structure
  • cleanup-branches.py - Remove merged branches
  • commit-analyzer.py - Analyze commit patterns

references/

  • workflows.md - Detailed workflow comparisons
  • troubleshooting.md - Common problems and solutions

# Supported AI Coding Agents

This skill is compatible with the SKILL.md standard and works with all major AI coding agents:

Learn more about the SKILL.md standard and how to use these skills with your preferred AI coding agent.