Agent Skillsrmyndharis/antigravity-skills › git-advanced-workflows

git-advanced-workflows

GitHub

掌握Git高级工作流,包括交互式变基、拣选提交、二分查找缺陷、多工作树并行开发及日志恢复。用于维护清晰历史、复杂分支协作、修复错误及从Git失误中恢复。

skills/git-advanced-workflows/SKILL.md rmyndharis/antigravity-skills

Trigger Scenarios

清理合并前的提交历史 跨分支应用特定提交 查找引入bug的提交 同时处理多个功能 从Git错误或丢失的提交中恢复 管理复杂的分支工作流 准备干净的PR 同步分叉的分支

Install

npx skills add rmyndharis/antigravity-skills --skill git-advanced-workflows -g -y
More Options

Use without installing

npx skills use rmyndharis/antigravity-skills@git-advanced-workflows

指定 Agent (Claude Code)

npx skills add rmyndharis/antigravity-skills --skill git-advanced-workflows -a claude-code -g -y

安装 repo 全部 skill

npx skills add rmyndharis/antigravity-skills --all -g -y

预览 repo 内 skill

npx skills add rmyndharis/antigravity-skills --list

SKILL.md

Frontmatter
{
    "name": "git-advanced-workflows",
    "description": "Master advanced Git workflows including rebasing, cherry-picking, bisect, worktrees, and reflog to maintain clean history and recover from any situation. Use when managing complex Git histories, collaborating on feature branches, or troubleshooting repository issues."
}

Git Advanced Workflows

Master advanced Git techniques to maintain clean history, collaborate effectively, and recover from any situation with confidence.

Do not use this skill when

  • The task is unrelated to git advanced workflows
  • You need a different domain or tool outside this scope

Instructions

  • Clarify goals, constraints, and required inputs.
  • Apply relevant best practices and validate outcomes.
  • Provide actionable steps and verification.

Use this skill when

  • Cleaning up commit history before merging
  • Applying specific commits across branches
  • Finding commits that introduced bugs
  • Working on multiple features simultaneously
  • Recovering from Git mistakes or lost commits
  • Managing complex branch workflows
  • Preparing clean PRs for review
  • Synchronizing diverged branches

Core Concepts

1. Interactive Rebase

Interactive rebase is the Swiss Army knife of Git history editing.

Common Operations:

  • pick: Keep commit as-is
  • reword: Change commit message
  • edit: Amend commit content
  • squash: Combine with previous commit
  • fixup: Like squash but discard message
  • drop: Remove commit entirely

Basic Usage:

# Rebase last 5 commits
git rebase -i HEAD~5

# Rebase all commits on current branch
git rebase -i $(git merge-base HEAD main)

# Rebase onto specific commit
git rebase -i abc123

2. Cherry-Picking

Apply specific commits from one branch to another without merging entire branches.

# Cherry-pick single commit
git cherry-pick abc123

# Cherry-pick range of commits (exclusive start)
git cherry-pick abc123..def456

# Cherry-pick without committing (stage changes only)
git cherry-pick -n abc123

# Cherry-pick and edit commit message
git cherry-pick -e abc123

3. Git Bisect

Binary search through commit history to find the commit that introduced a bug.

# Start bisect
git bisect start

# Mark current commit as bad
git bisect bad

# Mark known good commit
git bisect good v1.0.0

# Git will checkout middle commit - test it
# Then mark as good or bad
git bisect good  # or: git bisect bad

# Continue until bug found
# When done
git bisect reset

Automated Bisect:

# Use script to test automatically
git bisect start HEAD v1.0.0
git bisect run ./test.sh

# test.sh should exit 0 for good, 1-127 (except 125) for bad

4. Worktrees

Work on multiple branches simultaneously without stashing or switching.

# List existing worktrees
git worktree list

# Add new worktree for feature branch
git worktree add ../project-feature feature/new-feature

# Add worktree and create new branch
git worktree add -b bugfix/urgent ../project-hotfix main

# Remove worktree
git worktree remove ../project-feature

# Prune stale worktrees
git worktree prune

5. Reflog

Your safety net - tracks all ref movements, even deleted commits.

# View reflog
git reflog

# View reflog for specific branch
git reflog show feature/branch

# Restore deleted commit
git reflog
# Find commit hash
git checkout abc123
git branch recovered-branch

# Restore deleted branch
git reflog
git branch deleted-branch abc123

Practical Workflows

Workflow 1: Clean Up Feature Branch Before PR

# Start with feature branch
git checkout feature/user-auth

# Interactive rebase to clean history
git rebase -i main

# Example rebase operations:
# - Squash "fix typo" commits
# - Reword commit messages for clarity
# - Reorder commits logically
# - Drop unnecessary commits

# Force push cleaned branch (safe if no one else is using it)
git push --force-with-lease origin feature/user-auth

Workflow 2: Apply Hotfix to Multiple Releases

# Create fix on main
git checkout main
git commit -m "fix: critical security patch"

# Apply to release branches
git checkout release/2.0
git cherry-pick abc123

git checkout release/1.9
git cherry-pick abc123

# Handle conflicts if they arise
git cherry-pick --continue
# or
git cherry-pick --abort

Workflow 3: Find Bug Introduction

# Start bisect
git bisect start
git bisect bad HEAD
git bisect good v2.1.0

# Git checks out middle commit - run tests
npm test

# If tests fail
git bisect bad

# If tests pass
git bisect good

# Git will automatically checkout next commit to test
# Repeat until bug found

# Automated version
git bisect start HEAD v2.1.0
git bisect run npm test

Workflow 4: Multi-Branch Development

# Main project directory
cd ~/projects/myapp

# Create worktree for urgent bugfix
git worktree add ../myapp-hotfix hotfix/critical-bug

# Work on hotfix in separate directory
cd ../myapp-hotfix
# Make changes, commit
git commit -m "fix: resolve critical bug"
git push origin hotfix/critical-bug

# Return to main work without interruption
cd ~/projects/myapp
git fetch origin
git cherry-pick hotfix/critical-bug

# Clean up when done
git worktree remove ../myapp-hotfix

Workflow 5: Recover from Mistakes

# Accidentally reset to wrong commit
git reset --hard HEAD~5  # Oh no!

# Use reflog to find lost commits
git reflog
# Output shows:
# abc123 HEAD@{0}: reset: moving to HEAD~5
# def456 HEAD@{1}: commit: my important changes

# Recover lost commits
git reset --hard def456

# Or create branch from lost commit
git branch recovery def456

Advanced Techniques

Rebase vs Merge Strategy

When to Rebase:

  • Cleaning up local commits before pushing
  • Keeping feature branch up-to-date with main
  • Creating linear history for easier review

When to Merge:

  • Integrating completed features into main
  • Preserving exact history of collaboration
  • Public branches used by others
# Update feature branch with main changes (rebase)
git checkout feature/my-feature
git fetch origin
git rebase origin/main

# Handle conflicts
git status
# Fix conflicts in files
git add .
git rebase --continue

# Or merge instead
git merge origin/main

Autosquash Workflow

Automatically squash fixup commits during rebase.

# Make initial commit
git commit -m "feat: add user authentication"

# Later, fix something in that commit
# Stage changes
git commit --fixup HEAD  # or specify commit hash

# Make more changes
git commit --fixup abc123

# Rebase with autosquash
git rebase -i --autosquash main

# Git automatically marks fixup commits

Split Commit

Break one commit into multiple logical commits.

# Start interactive rebase
git rebase -i HEAD~3

# Mark commit to split with 'edit'
# Git will stop at that commit

# Reset commit but keep changes
git reset HEAD^

# Stage and commit in logical chunks
git add file1.py
git commit -m "feat: add validation"

git add file2.py
git commit -m "feat: add error handling"

# Continue rebase
git rebase --continue

Partial Cherry-Pick

Cherry-pick only specific files from a commit.

# Show files in commit
git show --name-only abc123

# Checkout specific files from commit
git checkout abc123 -- path/to/file1.py path/to/file2.py

# Stage and commit
git commit -m "cherry-pick: apply specific changes from abc123"

Best Practices

  1. Always Use --force-with-lease: Safer than --force, prevents overwriting others' work
  2. Rebase Only Local Commits: Don't rebase commits that have been pushed and shared
  3. Descriptive Commit Messages: Future you will thank present you
  4. Atomic Commits: Each commit should be a single logical change
  5. Test Before Force Push: Ensure history rewrite didn't break anything
  6. Keep Reflog Aware: Remember reflog is your safety net for 90 days
  7. Branch Before Risky Operations: Create backup branch before complex rebases
# Safe force push
git push --force-with-lease origin feature/branch

# Create backup before risky operation
git branch backup-branch
git rebase -i main
# If something goes wrong
git reset --hard backup-branch

Common Pitfalls

  • Rebasing Public Branches: Causes history conflicts for collaborators
  • Force Pushing Without Lease: Can overwrite teammate's work
  • Losing Work in Rebase: Resolve conflicts carefully, test after rebase
  • Forgetting Worktree Cleanup: Orphaned worktrees consume disk space
  • Not Backing Up Before Experiment: Always create safety branch
  • Bisect on Dirty Working Directory: Commit or stash before bisecting

Recovery Commands

# Abort operations in progress
git rebase --abort
git merge --abort
git cherry-pick --abort
git bisect reset

# Restore file to version from specific commit
git restore --source=abc123 path/to/file

# Undo last commit but keep changes
git reset --soft HEAD^

# Undo last commit and discard changes
git reset --hard HEAD^

# Recover deleted branch (within 90 days)
git reflog
git branch recovered-branch abc123

Resources

  • references/git-rebase-guide.md: Deep dive into interactive rebase
  • references/git-conflict-resolution.md: Advanced conflict resolution strategies
  • references/git-history-rewriting.md: Safely rewriting Git history
  • assets/git-workflow-checklist.md: Pre-PR cleanup checklist
  • assets/git-aliases.md: Useful Git aliases for advanced workflows
  • scripts/git-clean-branches.sh: Clean up merged and stale branches

Version History

  • e63f7dd Current 2026-07-05 09:32

Same Skill Collection

skills/accessibility-compliance-accessibility-audit/SKILL.md
skills/agent-orchestration-improve-agent/SKILL.md
skills/agent-orchestration-multi-agent-optimize/SKILL.md
skills/ai-engineer/SKILL.md
skills/airflow-dag-patterns/SKILL.md
skills/angular-migration/SKILL.md
skills/anti-reversing-techniques/SKILL.md
skills/api-design-principles/SKILL.md
skills/api-documenter/SKILL.md
skills/api-testing-observability-api-mock/SKILL.md
skills/application-performance-performance-optimization/SKILL.md
skills/architect-review/SKILL.md
skills/architecture-decision-records/SKILL.md
skills/architecture-patterns/SKILL.md
skills/arm-cortex-expert/SKILL.md
skills/article-illustrations/SKILL.md
skills/async-python-patterns/SKILL.md
skills/attack-tree-construction/SKILL.md
skills/auth-implementation-patterns/SKILL.md
skills/backend-architect/SKILL.md
skills/backend-development-feature-development/SKILL.md
skills/backend-security-coder/SKILL.md
skills/backtesting-frameworks/SKILL.md
skills/bash-defensive-patterns/SKILL.md
skills/bash-pro/SKILL.md
skills/bats-testing-patterns/SKILL.md
skills/bazel-build-optimization/SKILL.md
skills/billing-automation/SKILL.md
skills/binary-analysis-patterns/SKILL.md
skills/blockchain-developer/SKILL.md
skills/business-analyst/SKILL.md
skills/c-pro/SKILL.md
skills/c4-architecture-c4-architecture/SKILL.md
skills/c4-code/SKILL.md
skills/c4-component/SKILL.md
skills/c4-container/SKILL.md
skills/c4-context/SKILL.md
skills/changelog-automation/SKILL.md
skills/cicd-automation-workflow-automate/SKILL.md
skills/cloud-architect/SKILL.md
skills/code-documentation-code-explain/SKILL.md
skills/code-documentation-doc-generate/SKILL.md
skills/code-refactoring-context-restore/SKILL.md
skills/code-refactoring-refactor-clean/SKILL.md
skills/code-refactoring-tech-debt/SKILL.md
skills/code-review-ai-ai-review/SKILL.md
skills/code-review-excellence/SKILL.md
skills/code-reviewer/SKILL.md
skills/codebase-cleanup-deps-audit/SKILL.md
skills/codebase-cleanup-refactor-clean/SKILL.md
skills/codebase-cleanup-tech-debt/SKILL.md
skills/competitive-landscape/SKILL.md
skills/comprehensive-review-full-review/SKILL.md
skills/comprehensive-review-pr-enhance/SKILL.md
skills/conductor-implement/SKILL.md
skills/conductor-manage/SKILL.md
skills/conductor-new-track/SKILL.md
skills/conductor-revert/SKILL.md
skills/conductor-setup/SKILL.md
skills/conductor-status/SKILL.md
skills/conductor-validator/SKILL.md
skills/content-marketer/SKILL.md
skills/context-driven-development/SKILL.md
skills/context-management-context-restore/SKILL.md
skills/context-management-context-save/SKILL.md
skills/context-manager/SKILL.md
skills/cost-optimization/SKILL.md
skills/cpp-pro/SKILL.md
skills/cqrs-implementation/SKILL.md
skills/csharp-pro/SKILL.md
skills/customer-support/SKILL.md
skills/data-engineer/SKILL.md
skills/data-engineering-data-driven-feature/SKILL.md
skills/data-engineering-data-pipeline/SKILL.md
skills/data-quality-frameworks/SKILL.md
skills/data-scientist/SKILL.md
skills/data-storytelling/SKILL.md
skills/database-admin/SKILL.md
skills/database-architect/SKILL.md
skills/database-cloud-optimization-cost-optimize/SKILL.md
skills/database-migration/SKILL.md
skills/database-migrations-migration-observability/SKILL.md
skills/database-migrations-sql-migrations/SKILL.md
skills/database-optimizer/SKILL.md
skills/dbt-transformation-patterns/SKILL.md
skills/debugger/SKILL.md
skills/debugging-strategies/SKILL.md
skills/debugging-toolkit-smart-debug/SKILL.md
skills/defi-protocol-templates/SKILL.md
skills/dependency-management-deps-audit/SKILL.md
skills/dependency-upgrade/SKILL.md
skills/deployment-engineer/SKILL.md
skills/deployment-pipeline-design/SKILL.md
skills/deployment-validation-config-validate/SKILL.md
skills/devops-troubleshooter/SKILL.md
skills/distributed-debugging-debug-trace/SKILL.md
skills/distributed-tracing/SKILL.md
skills/django-pro/SKILL.md
skills/docs-architect/SKILL.md
skills/documentation-generation-doc-generate/SKILL.md
skills/dotnet-architect/SKILL.md
skills/dotnet-backend-patterns/SKILL.md
skills/dx-optimizer/SKILL.md
skills/e2e-testing-patterns/SKILL.md
skills/elixir-pro/SKILL.md
skills/embedding-strategies/SKILL.md
skills/employment-contract-templates/SKILL.md
skills/error-debugging-error-analysis/SKILL.md
skills/error-debugging-error-trace/SKILL.md
skills/error-debugging-multi-agent-review/SKILL.md
skills/error-detective/SKILL.md
skills/error-diagnostics-error-analysis/SKILL.md
skills/error-diagnostics-error-trace/SKILL.md
skills/error-diagnostics-smart-debug/SKILL.md
skills/error-handling-patterns/SKILL.md
skills/event-sourcing-architect/SKILL.md
skills/event-store-design/SKILL.md
skills/fastapi-pro/SKILL.md
skills/fastapi-templates/SKILL.md
skills/firmware-analyst/SKILL.md
skills/flutter-expert/SKILL.md
skills/framework-migration-code-migrate/SKILL.md
skills/framework-migration-deps-upgrade/SKILL.md
skills/framework-migration-legacy-modernize/SKILL.md
skills/frontend-developer/SKILL.md
skills/frontend-mobile-development-component-scaffold/SKILL.md
skills/frontend-mobile-security-xss-scan/SKILL.md
skills/frontend-security-coder/SKILL.md
skills/full-stack-orchestration-full-stack-feature/SKILL.md
skills/gdpr-data-handling/SKILL.md
skills/git-pr-workflows-git-workflow/SKILL.md
skills/git-pr-workflows-onboard/SKILL.md
skills/git-pr-workflows-pr-enhance/SKILL.md
skills/github-actions-templates/SKILL.md
skills/gitlab-ci-patterns/SKILL.md
skills/gitops-workflow/SKILL.md
skills/go-concurrency-patterns/SKILL.md
skills/godot-gdscript-patterns/SKILL.md
skills/golang-pro/SKILL.md
skills/grafana-dashboards/SKILL.md
skills/graphql-architect/SKILL.md
skills/haskell-pro/SKILL.md
skills/helm-chart-scaffolding/SKILL.md
skills/hr-pro/SKILL.md
skills/hybrid-cloud-architect/SKILL.md
skills/hybrid-cloud-networking/SKILL.md
skills/hybrid-search-implementation/SKILL.md
skills/incident-responder/SKILL.md
skills/incident-response-incident-response/SKILL.md
skills/incident-response-smart-fix/SKILL.md
skills/incident-runbook-templates/SKILL.md
skills/ios-developer/SKILL.md
skills/istio-traffic-management/SKILL.md
skills/java-pro/SKILL.md
skills/javascript-pro/SKILL.md
skills/javascript-testing-patterns/SKILL.md
skills/javascript-typescript-typescript-scaffold/SKILL.md
skills/julia-pro/SKILL.md
skills/k8s-manifest-generator/SKILL.md
skills/k8s-security-policies/SKILL.md
skills/kpi-dashboard-design/SKILL.md
skills/kubernetes-architect/SKILL.md
skills/langchain-architecture/SKILL.md
skills/legacy-modernizer/SKILL.md
skills/legal-advisor/SKILL.md
skills/linkerd-patterns/SKILL.md
skills/llm-application-dev-ai-assistant/SKILL.md
skills/llm-application-dev-langchain-agent/SKILL.md
skills/llm-application-dev-prompt-optimize/SKILL.md
skills/llm-evaluation/SKILL.md
skills/machine-learning-ops-ml-pipeline/SKILL.md
skills/malware-analyst/SKILL.md
skills/market-sizing-analysis/SKILL.md
skills/memory-forensics/SKILL.md
skills/memory-safety-patterns/SKILL.md
skills/mermaid-expert/SKILL.md
skills/microservices-patterns/SKILL.md
skills/minecraft-bukkit-pro/SKILL.md
skills/ml-engineer/SKILL.md
skills/ml-pipeline-workflow/SKILL.md
skills/mlops-engineer/SKILL.md
skills/mobile-developer/SKILL.md
skills/mobile-security-coder/SKILL.md
skills/modern-javascript-patterns/SKILL.md
skills/monorepo-architect/SKILL.md
skills/monorepo-management/SKILL.md
skills/mtls-configuration/SKILL.md
skills/multi-cloud-architecture/SKILL.md
skills/multi-platform-apps-multi-platform/SKILL.md
skills/network-engineer/SKILL.md
skills/nextjs-app-router-patterns/SKILL.md
skills/nft-standards/SKILL.md
skills/nodejs-backend-patterns/SKILL.md
skills/nx-workspace-patterns/SKILL.md
skills/observability-engineer/SKILL.md
skills/observability-monitoring-monitor-setup/SKILL.md
skills/observability-monitoring-slo-implement/SKILL.md
skills/on-call-handoff-patterns/SKILL.md
skills/openapi-spec-generation/SKILL.md
skills/payment-integration/SKILL.md
skills/paypal-integration/SKILL.md
skills/pci-compliance/SKILL.md
skills/performance-engineer/SKILL.md
skills/performance-testing-review-ai-review/SKILL.md
skills/performance-testing-review-multi-agent-review/SKILL.md
skills/php-pro/SKILL.md
skills/posix-shell-pro/SKILL.md
skills/postgresql/SKILL.md
skills/postmortem-writing/SKILL.md
skills/projection-patterns/SKILL.md
skills/prometheus-configuration/SKILL.md
skills/prompt-engineer/SKILL.md
skills/prompt-engineering-patterns/SKILL.md
skills/protocol-reverse-engineering/SKILL.md
skills/python-packaging/SKILL.md
skills/python-performance-optimization/SKILL.md
skills/python-pro/SKILL.md
skills/python-testing-patterns/SKILL.md
skills/quant-analyst/SKILL.md
skills/rag-implementation/SKILL.md
skills/react-modernization/SKILL.md
skills/react-native-architecture/SKILL.md
skills/react-state-management/SKILL.md
skills/reference-builder/SKILL.md
skills/reverse-engineer/SKILL.md
skills/risk-manager/SKILL.md
skills/risk-metrics-calculation/SKILL.md
skills/ruby-pro/SKILL.md
skills/rust-async-patterns/SKILL.md
skills/rust-pro/SKILL.md
skills/saga-orchestration/SKILL.md
skills/sales-automator/SKILL.md
skills/sast-configuration/SKILL.md
skills/scala-pro/SKILL.md
skills/screen-reader-testing/SKILL.md
skills/search-specialist/SKILL.md
skills/secrets-management/SKILL.md
skills/security-auditor/SKILL.md
skills/security-compliance-compliance-check/SKILL.md
skills/security-requirement-extraction/SKILL.md
skills/security-scanning-security-dependencies/SKILL.md
skills/security-scanning-security-hardening/SKILL.md
skills/security-scanning-security-sast/SKILL.md
skills/seo-authority-builder/SKILL.md
skills/seo-cannibalization-detector/SKILL.md
skills/seo-content-auditor/SKILL.md
skills/seo-content-planner/SKILL.md
skills/seo-content-refresher/SKILL.md
skills/seo-content-writer/SKILL.md
skills/seo-keyword-strategist/SKILL.md
skills/seo-meta-optimizer/SKILL.md
skills/seo-snippet-hunter/SKILL.md
skills/seo-structure-architect/SKILL.md
skills/service-mesh-expert/SKILL.md
skills/service-mesh-observability/SKILL.md
skills/shellcheck-configuration/SKILL.md
skills/similarity-search-patterns/SKILL.md
skills/slo-implementation/SKILL.md
skills/solidity-security/SKILL.md
skills/spark-optimization/SKILL.md
skills/sql-optimization-patterns/SKILL.md
skills/sql-pro/SKILL.md
skills/startup-analyst/SKILL.md
skills/startup-business-analyst-business-case/SKILL.md
skills/startup-business-analyst-financial-projections/SKILL.md
skills/startup-business-analyst-market-opportunity/SKILL.md
skills/startup-financial-modeling/SKILL.md
skills/startup-metrics-framework/SKILL.md
skills/stride-analysis-patterns/SKILL.md
skills/stripe-integration/SKILL.md
skills/systems-programming-rust-project/SKILL.md
skills/tailwind-design-system/SKILL.md
skills/tdd-orchestrator/SKILL.md
skills/tdd-workflows-tdd-green/SKILL.md
skills/tdd-workflows-tdd-red/SKILL.md
skills/team-collaboration-issue/SKILL.md
skills/team-collaboration-standup-notes/SKILL.md
skills/team-composition-analysis/SKILL.md
skills/temporal-python-pro/SKILL.md
skills/temporal-python-testing/SKILL.md
skills/terraform-module-library/SKILL.md
skills/terraform-specialist/SKILL.md
skills/test-automator/SKILL.md
skills/threat-mitigation-mapping/SKILL.md
skills/threat-modeling-expert/SKILL.md
skills/track-management/SKILL.md
skills/turborepo-caching/SKILL.md
skills/tutorial-engineer/SKILL.md
skills/typescript-advanced-types/SKILL.md
skills/typescript-pro/SKILL.md
skills/ui-ux-designer/SKILL.md
skills/ui-visual-validator/SKILL.md
skills/unit-testing-test-generate/SKILL.md
skills/unity-developer/SKILL.md
skills/unity-ecs-patterns/SKILL.md
skills/uv-package-manager/SKILL.md
skills/vector-database-engineer/SKILL.md
skills/vector-index-tuning/SKILL.md
skills/wcag-audit-patterns/SKILL.md
skills/web3-testing/SKILL.md
skills/workflow-orchestration-patterns/SKILL.md
skills/workflow-patterns/SKILL.md
skills/tdd-workflows-tdd-cycle/SKILL.md
skills/tdd-workflows-tdd-refactor/SKILL.md

Metadata

Files
0
Version
e63f7dd
Hash
0566a20d
Indexed
2026-07-05 09:32

Accueil - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-07-08 20:28
浙ICP备14020137号-1 $Carte des visiteurs$