home / skills / aj-geddes / useful-ai-prompts / git-workflow-strategy

git-workflow-strategy skill

/skills/git-workflow-strategy

This skill helps teams implement and optimize Git workflows such as GitFlow, GitHub Flow, and trunk-based development for safer collaboration.

npx playbooks add skill aj-geddes/useful-ai-prompts --skill git-workflow-strategy

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

Files (1)
SKILL.md
6.0 KB
---
name: git-workflow-strategy
description: Master Git workflows including GitFlow, GitHub Flow, Trunk-Based Development. Configure branches, merge strategies, and collaboration patterns for team environments.
---

# Git Workflow Strategy

## Overview

Establish efficient Git workflows that support team collaboration, code quality, and deployment readiness through structured branching strategies and merge patterns.

## When to Use

- Team collaboration setup
- Release management
- Feature development coordination
- Hotfix procedures
- Code review processes
- CI/CD integration planning

## Implementation Examples

### 1. **GitFlow Workflow Setup**

```bash
# Initialize GitFlow
git flow init -d

# Start a feature
git flow feature start new-feature
# Work on feature
git add .
git commit -m "feat: implement new feature"
git flow feature finish new-feature

# Start a release
git flow release start 1.0.0
# Update version numbers, changelog
git add .
git commit -m "chore: bump version to 1.0.0"
git flow release finish 1.0.0

# Create hotfix
git flow hotfix start 1.0.1
# Fix critical bug
git add .
git commit -m "fix: critical bug in production"
git flow hotfix finish 1.0.1
```

### 2. **GitHub Flow Workflow**

```bash
# Clone and setup
git clone https://github.com/org/repo.git
cd repo

# Create feature branch from main
git checkout -b feature/add-auth-service
git add .
git commit -m "feat: add authentication service"
git push origin feature/add-auth-service

# Push changes, create PR, request reviews
# After approval and CI passes, merge to main
git checkout main
git pull origin main
git merge feature/add-auth-service
git push origin main

# Deploy and cleanup
git branch -d feature/add-auth-service
git push origin -d feature/add-auth-service
```

### 3. **Trunk-Based Development**

```bash
# Create short-lived feature branch
git checkout -b feature/toggle-feature
# Keep commits small and atomic
git add specific_file.js
git commit -m "feat: add feature flag configuration"

# Rebase on main frequently
git fetch origin
git rebase origin/main

# Create PR with small changeset
git push origin feature/toggle-feature

# After PR merge, delete branch
git checkout main
git pull origin main
git branch -d feature/toggle-feature
```

### 4. **Git Configuration for Workflows**

```bash
# Configure user
git config --global user.name "Developer Name"
git config --global user.email "[email protected]"

# Set default branch
git config --global init.defaultBranch main

# Configure merge strategy
git config --global pull.ff only
git config --global merge.ff false

# Enable rerere (reuse recorded resolution)
git config --global rerere.enabled true

# Configure commit message format
git config --global commit.template ~/.gitmessage

# Setup branch protection rules
git config --global branch.main.rebase true
git config --global branch.develop.rebase true
```

### 5. **Branch Naming Conventions**

```bash
# Feature branches
git checkout -b feature/user-authentication
git checkout -b feature/JIRA-123-payment-integration

# Bug fix branches
git checkout -b bugfix/JIRA-456-login-timeout
git checkout -b fix/null-pointer-exception

# Release branches
git checkout -b release/v2.1.0
git checkout -b release/2024-Q1

# Hotfix branches
git checkout -b hotfix/critical-security-patch
git checkout -b hotfix/v2.0.1

# Chore branches
git checkout -b chore/update-dependencies
git checkout -b chore/refactor-auth-module
```

### 6. **Merge Strategy Script**

```bash
#!/bin/bash
# merge-with-strategy.sh

BRANCH=$1
STRATEGY=${2:-"squash"}

if [ -z "$BRANCH" ]; then
    echo "Usage: ./merge-with-strategy.sh <branch> [squash|rebase|merge]"
    exit 1
fi

# Update main
git checkout main
git pull origin main

case "$STRATEGY" in
    squash)
        git merge --squash origin/$BRANCH
        git commit -m "Merge $BRANCH"
        ;;
    rebase)
        git rebase origin/$BRANCH
        ;;
    merge)
        git merge --no-ff origin/$BRANCH
        ;;
    *)
        echo "Unknown strategy: $STRATEGY"
        exit 1
        ;;
esac

git push origin main
git push origin -d $BRANCH
```

### 7. **Collaborative Workflow with Code Review**

```bash
# Developer creates feature
git checkout -b feature/search-optimization
# Make changes
git add .
git commit -m "perf: optimize search algorithm"
git push origin feature/search-optimization

# Create pull request with detailed description
# Reviewer reviews and suggests changes

# Developer makes requested changes
git add .
git commit -m "refactor: improve search efficiency per review"
git push origin feature/search-optimization

# After approval
git checkout main
git pull origin main
git merge feature/search-optimization
git push origin main

# Cleanup
git branch -d feature/search-optimization
git push origin -d feature/search-optimization
```

## Best Practices

### ✅ DO
- Choose workflow matching team size and release cycle
- Keep feature branches short-lived (< 3 days)
- Use descriptive branch names with type prefix
- Require code review before merging to main
- Enforce protection rules on main/release branches
- Rebase frequently to minimize conflicts
- Write atomic, logical commits
- Keep commit messages clear and consistent

### ❌ DON'T
- Commit directly to main branch
- Create long-lived feature branches
- Use vague branch names (dev, test, temp)
- Merge without code review
- Mix multiple features in one branch
- Force push to shared branches
- Ignore failing CI checks
- Merge with merge commits in TBD

## Branch Protection Rules (GitHub)

```yaml
# .github/branch-protection-rules.yml
branches:
  main:
    required_status_checks: true
    required_code_review: true
    dismiss_stale_reviews: true
    require_branches_up_to_date: true
    enforce_admins: true
    required_signatures: false
```

## Resources

- [Git Branching Strategies](https://git-scm.com/book/en/v2/Git-Branching-Branching-Workflows)
- [GitHub Flow Guide](https://guides.github.com/introduction/flow/)
- [A Successful Git Branching Model](https://nvie.com/posts/a-successful-git-branching-model/)
- [Trunk Based Development](https://trunkbaseddevelopment.com/)

Overview

This skill teaches how to choose, configure, and operate Git branching workflows—GitFlow, GitHub Flow, and Trunk-Based Development—to improve team collaboration, release cadence, and deployment safety. It describes branch naming, merge strategies, CI/CD integration, and practical scripts to automate merges and cleanup. The guidance is focused on outcomes: fewer conflicts, reliable releases, and clearer code review processes.

How this skill works

The skill inspects team size, release cadence, and deployment requirements to recommend an appropriate workflow and configuration. It provides concrete commands and a merge-strategy script to standardize merges (squash, rebase, merge), examples for branch naming conventions, and configuration snippets for Git and branch protection rules. It also outlines collaboration patterns and CI guardrails to enforce quality.

When to use it

  • Setting up version control for a new or scaling engineering team
  • Defining release management and hotfix procedures
  • Standardizing feature development and pull request workflows
  • Integrating Git with CI/CD pipelines and branch protection
  • Reducing merge conflicts during frequent collaboration

Best practices

  • Pick a workflow aligned to team size and release frequency (GitFlow for complex release processes, GitHub Flow for continuous deploys, Trunk for fast iterations)
  • Keep feature branches short-lived and focused (< 3 days when possible)
  • Use descriptive, prefixed branch names (feature/, bugfix/, hotfix/, release/)
  • Require code review and passing CI before merging to protected branches
  • Rebase frequently to keep branches up to date and minimize conflicts
  • Use consistent commit message templates and atomic commits

Example use cases

  • GitFlow: managing parallel releases, staging and production branches for enterprise products
  • GitHub Flow: small teams deploying multiple times per day with PR-based releases
  • Trunk-Based Development: high-velocity teams using feature toggles and short-lived branches
  • Merge strategy script: automate consistent merges and branch cleanup across repositories
  • Branch protection: enforce CI, review, and up-to-date rules on main/release branches

FAQ

Which workflow should my team choose?

Choose based on team size and release cadence: GitFlow suits formal release cycles, GitHub Flow fits continuous delivery, and Trunk-Based Development is best for high-velocity teams using feature flags.

How do I reduce merge conflicts?

Keep branches short-lived, rebase frequently on main, make small atomic commits, and require branches to be up to date before merging.