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 ===
@defaulttask pre-commit: [lint, format-check, test-quick] @description "Run before every commit" echo "Pre-commit checks passed!"
task lint: @description "Run all linters" @needs npm npm run lint
task format-check: @description "Check code formatting" @needs npm npx prettier --check "src/**/*.{ts,tsx,js,json,css}"
task test-quick: @description "Run fast unit tests only" @needs npm npm test -- --testPathPattern="unit" --bail
# === Branch Workflows ===
task branch-check: @description "Verify clean working directory" @if neq($(git status --porcelain), "") echo "Error: Working directory is not clean" git status --short exit 1 @end echo "Working directory is clean"
task branch-sync: @description "Sync with upstream main" @pre echo "Syncing with upstream..." git fetch origin git rebase origin/main @post echo "Branch synced with main"
task branch-cleanup: @description "Delete merged local branches" @confirm "Delete merged branches?" git branch --merged main | grep -v "main" | xargs -r git branch -d echo "Cleaned up merged branches"
# === Feature Branch Workflow ===
task feature-start name: @description "Start a new feature branch" git checkout main git pull origin main git checkout -b "feature/{{name}}" echo "Created feature/{{name}}"
task feature-finish: @description "Finish current feature branch" @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 ===
task commit-fix: @description "Create a fix commit" @confirm "Stage all changes and commit as fix?" git add -A git commit -m "fix: {{$1}}"
task commit-feat: @description "Create a feature commit" @confirm "Stage all changes and commit as feature?" git add -A git commit -m "feat: {{$1}}"
task commit-docs: @description "Create a docs commit" git add -A git commit -m "docs: {{$1}}"
task commit-chore: @description "Create a chore commit" git add -A git commit -m "chore: {{$1}}"
# === Tagging ===
task tag-version: @description "Create version tag" @require VERSION @confirm "Create tag v$VERSION?" git tag -a "v$VERSION" -m "Release v$VERSION" echo "Created tag v$VERSION"
task tag-push: @description "Push all tags to origin" git push origin --tags echo "Tags pushed"
# === Git Hooks Setup ===
task hooks-install: @description "Install git hooks" 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!"
task hooks-uninstall: @description "Remove git hooks" rm -f .git/hooks/pre-commit rm -f .git/hooks/commit-msg echo "Git hooks removed"
# === Utility ===
task status: @description "Show detailed git status" @quiet echo "=== Branch ===" git branch --show-current echo "" echo "=== Status ===" git status --short echo "" echo "=== Recent Commits ===" git log --oneline -5
task log: @description "Pretty git 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()