home / skills / autumnsgrove / groveengine / git-workflows

git-workflows skill

/.claude/skills/git-workflows

This skill helps you manage Git workflows using Conventional Commits with safe branching, enabling clear history and rapid collaboration.

npx playbooks add skill autumnsgrove/groveengine --skill git-workflows

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
4.3 KB
---
name: git-workflows
description: Execute git operations using Conventional Commits format with proper branching strategies and safe workflows. Use when making commits, managing branches, or performing git operations.
---

# Git Workflows Skill

## When to Activate

Activate this skill when:
- Making git commits
- Creating or merging branches
- Initializing repositories
- Resolving merge conflicts
- Reviewing git history

## Conventional Commits Format

```
<type>: <brief description>

<optional body>

<optional footer>
```

### Commit Types

| Type | Purpose | Example |
|------|---------|---------|
| `feat` | New feature | `feat: Add user authentication` |
| `fix` | Bug fix | `fix: Correct validation error` |
| `docs` | Documentation | `docs: Update README` |
| `style` | Code formatting | `style: Format with Black` |
| `refactor` | Code restructure | `refactor: Extract helper function` |
| `test` | Add/modify tests | `test: Add auth tests` |
| `chore` | Maintenance | `chore: Update dependencies` |
| `perf` | Performance | `perf: Optimize query speed` |

## Quick Reference

```bash
# Check status
git status
git diff --stat

# Stage and commit
git add .
git commit -m "feat: add new feature"

# View history
git log --oneline -5
git log --graph --oneline --all

# Undo operations
git restore <file>              # Discard changes
git restore --staged <file>     # Unstage
git reset HEAD~1                # Undo last commit (keep changes)
```

## Commit Examples

### Feature
```bash
git commit -m "feat: Add dark mode toggle

- Implement theme switching logic
- Add localStorage persistence
- Update CSS variables"
```

### Bug Fix
```bash
git commit -m "fix: Correct timezone handling bug

Fixes off-by-one error in date calculations.

Closes #123"
```

### Breaking Change
```bash
git commit -m "feat!: Replace XML config with YAML

BREAKING CHANGE: XML configuration no longer supported.
See docs/migration.md for upgrade instructions."
```

## Branching Strategy

### Feature Branches
```bash
# Create and switch
git checkout -b feature/user-auth

# Work and commit
git add .
git commit -m "feat: add JWT authentication"

# Merge back
git checkout main
git merge feature/user-auth
git branch -d feature/user-auth
```

### Branch Naming
```
feature/feature-name    # New features
fix/bug-description     # Bug fixes
experiment/new-idea     # Experiments
release/v1.0.0          # Releases
```

## Repository Setup

```bash
# Initialize new repo
git init

# Create .gitignore
cat > .gitignore << 'EOF'
secrets.json
*.log
__pycache__/
.DS_Store
.venv/
node_modules/
.env
EOF

# Initial commit
git add .
git commit -m "chore: initialize repository"
```

## Stashing Changes

```bash
# Stash current work
git stash push -m "WIP: auth feature"

# List stashes
git stash list

# Apply most recent
git stash pop

# Apply specific stash
git stash apply stash@{1}
```

## Undoing Changes

### Git Restore (Recommended)
```bash
git restore file.py           # Discard changes
git restore --staged file.py  # Unstage
```

### Git Reset
```bash
git reset --soft HEAD~1  # Undo commit, keep staged
git reset HEAD~1         # Undo commit, keep unstaged
git reset --hard HEAD~1  # Undo commit, discard (DANGEROUS)
```

### Git Revert (Safe for Shared History)
```bash
git revert abc1234  # Create new commit undoing changes
```

## Merge Conflicts

```bash
# After conflict:
git status  # See conflicted files

# Edit files to resolve:
# <<<<<<< HEAD
# Your changes
# =======
# Incoming changes
# >>>>>>> feature-branch

# Complete merge
git add resolved-file.py
git commit
```

## Best Practices

### DO ✅
- Use conventional commit format
- One logical change per commit
- Keep subject under 50 characters
- Use imperative mood ("Add" not "Added")
- Add body for complex changes

### DON'T ❌
- Use vague messages ("Update files")
- Combine multiple concerns
- Use past tense ("Added feature")
- End subject with period

## Troubleshooting

### Committed to wrong branch
```bash
git log --oneline -1  # Note commit hash
git checkout correct-branch
git cherry-pick abc1234
git checkout wrong-branch
git reset --hard HEAD~1
```

### Lost commits
```bash
git reflog  # Find lost commit
git checkout abc1234
git checkout -b recovery-branch
```

## Related Resources

See `AgentUsage/git_guide.md` for complete documentation including:
- Breaking change handling
- Dev/main branch strategy
- Semantic versioning integration
- Automation tools

Overview

This skill automates and guides safe Git operations using Conventional Commits and recommended branching strategies. It helps you create clear commits, manage branches, resolve conflicts, and undo changes in a multi-tenant TypeScript blog platform workflow. The focus is on predictable history, traceable changes, and repeatable release patterns.

How this skill works

The skill validates commit messages against the Conventional Commits format, suggests appropriate commit types, and enforces short, imperative subjects. It provides step-by-step commands for common tasks: creating feature branches, merging to main, stashing work, and resolving merge conflicts. It also recommends safe undo options (revert, restore, reset) depending on whether history is shared.

When to use it

  • Making commits to ensure messages follow Conventional Commits and are review-friendly
  • Creating, naming, and merging feature, fix, experiment, or release branches
  • Initializing a new repository or preparing initial project scaffolding
  • Resolving merge conflicts and completing merges safely
  • Undoing or recovering commits without corrupting shared history
  • Reviewing git history before releases or code reviews

Best practices

  • Use Conventional Commits: type: short subject, optional body and footer
  • One logical change per commit; keep subject under ~50 characters
  • Prefer imperative mood (Add, Fix, Update) and avoid trailing periods
  • Name branches by purpose: feature/, fix/, experiment/, release/
  • Use git revert for shared history and git reset/restore only for local fixes
  • Stash WIP changes before switching branches and pop/apply explicitly

Example use cases

  • Add a new authentication feature: create feature/auth, commit as feat:, merge to main and delete branch
  • Fix a timezone bug in the blog scheduler: branch fix/timezone, commit as fix:, include Closes #issue in footer
  • Prepare a release: create release/v1.2.0 branch, aggregate changelog from feat/ and fix/ commits
  • Recover a lost commit: use git reflog to find hash, create recovery branch and cherry-pick
  • Resolve CI merge conflict: checkout target branch, merge feature branch, edit conflicts, git add and commit

FAQ

When should I use git revert vs git reset?

Use git revert to safely undo changes in shared history by creating a new commit. Use git reset (soft/mixed/hard) only for local, unpushed commits; hard reset discards work and is destructive.

How do I format a breaking change in Conventional Commits?

Include a trailing ! after the type (e.g., feat!) and add a BREAKING CHANGE: section in the commit body explaining migration steps.