Git Automation
Streamline your Git workflow with automated commits, branch management, and pre-commit hooks.
Complete Jakefile
Section titled “Complete Jakefile”# Git Workflow Jakefile# =====================
@dotenv
# === Pre-commit Checks ===
@default@description "Run before every commit"task pre-commit: [lint, format-check, test-quick] echo "Pre-commit checks passed!"
@description "Run all linters"task lint: @needs npm npm run lint
@description "Check code formatting"task format-check: @needs npm npx prettier --check "src/**/*.{ts,tsx,js,json,css}"
@description "Run fast unit tests only"task test-quick: @needs npm npm test -- --testPathPattern="unit" --bail
# === Branch Workflows ===
@description "Verify clean working directory"task branch-check: @if neq($(git status --porcelain), "") echo "Error: Working directory is not clean" git status --short exit 1 @end echo "Working directory is clean"
@description "Sync with upstream main"task branch-sync: @pre echo "Syncing with upstream..." git fetch origin git rebase origin/main @post echo "Branch synced with main"
@description "Delete merged local branches"task branch-cleanup: @confirm "Delete merged branches?" git branch --merged main | grep -v "main" | xargs -r git branch -d echo "Cleaned up merged branches"
# === Feature Branch Workflow ===
@description "Start a new feature branch"task feature-start name: git checkout main git pull origin main git checkout -b "feature/{{name}}" echo "Created feature/{{name}}"
@description "Finish current feature branch"task feature-finish: @pre echo "Running final checks..." jake pre-commit @confirm "Merge feature branch?"
branch=$(git branch --show-current) git checkout main git pull origin main git merge --no-ff "$branch" -m "Merge $branch" git branch -d "$branch" echo "Merged and cleaned up $branch"
# === Commit Helpers ===
@description "Create a fix commit"task commit-fix: @confirm "Stage all changes and commit as fix?" git add -A git commit -m "fix: {{$1}}"
@description "Create a feature commit"task commit-feat: @confirm "Stage all changes and commit as feature?" git add -A git commit -m "feat: {{$1}}"
@description "Create a docs commit"task commit-docs: git add -A git commit -m "docs: {{$1}}"
@description "Create a chore commit"task commit-chore: git add -A git commit -m "chore: {{$1}}"
# === Tagging ===
@description "Create version tag"task tag-version: @require VERSION @confirm "Create tag v$VERSION?" git tag -a "v$VERSION" -m "Release v$VERSION" echo "Created tag v$VERSION"
@description "Push all tags to origin"task tag-push: git push origin --tags echo "Tags pushed"
# === Git Hooks Setup ===
@description "Install git hooks"task hooks-install: mkdir -p .git/hooks
echo '#!/bin/sh' > .git/hooks/pre-commit echo 'jake pre-commit' >> .git/hooks/pre-commit chmod +x .git/hooks/pre-commit
echo "Git hooks installed!"
@description "Remove git hooks"task hooks-uninstall: rm -f .git/hooks/pre-commit rm -f .git/hooks/commit-msg echo "Git hooks removed"
# === Utility ===
@description "Show detailed git status"task status: @quiet echo "=== Branch ===" git branch --show-current echo "" echo "=== Status ===" git status --short echo "" echo "=== Recent Commits ===" git log --oneline -5
@description "Pretty git log"task log: git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit -20jake pre-commit # Run before committingjake feature-start user-auth # Start feature branchjake commit-feat "add user login" # Conventional commitjake branch-cleanup # Delete merged branchesjake hooks-install # Set up git hooksKey Features
Section titled “Key Features”Conventional Commits
Section titled “Conventional Commits”Consistent commit messages with helpers:
task commit-feat: git add -A git commit -m "feat: {{$1}}"jake commit-feat "add user authentication"# Creates: feat: add user authenticationPre-commit Hooks
Section titled “Pre-commit Hooks”Install Jake as your pre-commit hook:
task hooks-install: echo 'jake pre-commit' >> .git/hooks/pre-commit chmod +x .git/hooks/pre-commitFeature Branch Workflow
Section titled “Feature Branch Workflow”Streamlined GitFlow-style workflow:
jake feature-start login-page # Create feature/login-page# ... work on feature ...jake pre-commit # Validate changesjake feature-finish # Merge back to mainBranch Safety
Section titled “Branch Safety”Check for clean working directory before operations:
task branch-check: @if neq($(git status --porcelain), "") echo "Error: Working directory is not clean" exit 1 @endCustomization
Section titled “Customization”Different Test Runners
Section titled “Different Test Runners”Adjust for your stack:
task test-quick: @needs pytest pytest tests/unit -x --tb=shortAdditional Commit Types
Section titled “Additional Commit Types”Add more conventional commit types:
task commit-refactor: git add -A git commit -m "refactor: {{$1}}"
task commit-perf: git add -A git commit -m "perf: {{$1}}"
task commit-test: git add -A git commit -m "test: {{$1}}"See Also
Section titled “See Also”- Positional Arguments - Using
{{$1}} - Conditionals -
@ifandneq()