Token导航 LogoToken导航TokenDH.com
研究检索需要联网github未标认证来源可访问clear审计提醒

git-advancedgit 高级

Agent Skill

git-advanced 用于查找、检索和筛选相关信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要根据关键词、任务场景或来源线索快速定位候选结果时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

490

周安装

20

GitHub Stars

8

下载量

158
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

3

许可证

MIT

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:git-advanced(git 高级)
来源仓库:https://github.com/vamseeachanta/workspace-hub
仓库路径:skills/git-advanced
安装命令:
npx skills add https://github.com/vamseeachanta/workspace-hub --skill git-advanced
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。不同来源提供的安装方式可能略有差异;本站展示可直接复制的安装命令,安装前请核对来源页面。

skills.shnpx skills
npx skills add https://github.com/vamseeachanta/workspace-hub --skill git-advanced

简介

git-advanced 用于查找、检索和筛选相关信息。

  • 适合在 Codex、Claude、Cursor、Gemini CLI 中根据关键词或任务场景快速定位候选结果。
  • 通过 npx skills add 命令从指定仓库安装,需结合原始 README 确认具体用法。
  • 安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。
  • 当前暂无更多细节,建议参考来源仓库了解具体实现方式。

SKILL.md

Git Advanced Skill

Master advanced git workflows for efficient version control. This skill covers interactive rebase, worktrees, bisect, rerere, reflog, hooks, and patterns for monorepos and submodules.

When to Use This Skill

USE when:

  • Managing complex branch strategies
  • Working on multiple features simultaneously
  • Hunting down bugs with bisect
  • Maintaining clean commit history
  • Setting up team workflows with hooks
  • Managing multi-repo dependencies
  • Recovering from git mistakes

DON'T USE when:

  • Simple linear development (basic git suffices)
  • Solo projects with simple history
  • When team isn't familiar with advanced git
  • Time-critical fixes (use simple commits)

Prerequisites

Installation

Git Configuration:

# Verify git version (2.23+ recommended)
git --version

# Global configuration
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"

# Recommended settings
git config --global init.defaultBranch main
git config --global pull.rebase true
git config --global push.autoSetupRemote true
git config --global rerere.enabled true
git config --global core.autocrlf input
git config --global core.editor "vim"

# Better diff
git config --global diff.algorithm histogram
git config --global merge.conflictStyle diff3

GitHub CLI (optional):

# macOS
brew install gh

# Linux
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
sudo apt update
sudo apt install gh

# Authenticate
gh auth login

Pre-commit (for hooks):

# Install pre-commit
pip install pre-commit

# Or with homebrew
brew install pre-commit

Core Capabilities

1. Interactive Rebase

Basic Interactive Rebase:

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

# Rebase onto main
git rebase -i main

# Rebase from specific commit
git rebase -i abc123^

Interactive Rebase Commands:

pick   abc123 First commit     # Use commit as-is
reword def456 Second commit    # Edit commit message
edit   ghi789 Third commit     # Stop to amend
squash jkl012 Fourth commit    # Combine with previous
fixup  mno345 Fifth commit     # Combine, discard message
drop   pqr678 Sixth commit     # Remove commit

Common Rebase Workflows:

# Squash all commits into one
git rebase -i main
# Change all but first 'pick' to 'squash'

# Reorder commits
git rebase -i HEAD~3
# Rearrange the pick lines

# Split a commit
git rebase -i HEAD~3
# Change 'pick' to 'edit' on target commit
git reset HEAD^
git add -p  # Add pieces
git commit -m "First part"
git add .
git commit -m "Second part"
git rebase --continue

# Edit commit message
git rebase -i HEAD~3
# Change 'pick' to 'reword'

Autosquash Pattern:

# Create fixup commit
git commit --fixup=abc123

# Create squash commit
git commit --squash=abc123

# Apply autosquash
git rebase -i --autosquash main

# Enable autosquash by default
git config --global rebase.autosquash true

2. Git Worktrees

Basic Worktree Usage:

# List worktrees
git worktree list

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

# Add worktree with new branch
git worktree add -b hotfix/urgent ../hotfix-urgent main

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

# Prune stale worktrees
git worktree prune

Worktree Workflow:

# Project structure
workspace/
├── main/           # Main development
├── feature-auth/   # Feature branch
├── hotfix-critical/# Hotfix branch
└── experiment/     # Experimental work

# Setup
cd main
git worktree add ../feature-auth feature/authentication
git worktree add ../hotfix-critical -b hotfix/critical-bug
git worktree add ../experiment -b experiment/new-approach

# Work on feature
cd ../feature-auth
# make changes...
git commit -am "Add authentication"

# Quick switch to fix bug
cd ../hotfix-critical
# fix bug...
git commit -am "Fix critical bug"
git push

# Back to feature
cd ../feature-auth

Worktree Helper Script:

#!/bin/bash
# scripts/worktree.sh
# ABOUTME: Git worktree management helper
# ABOUTME: Simplifies creating and managing worktrees

set -e

WORKTREE_BASE="${WORKTREE_BASE:-$(dirname $(git rev-parse --git-dir))}"

case "$1" in
    add)
        BRANCH="$2"
        DIR="${3:-$WORKTREE_BASE/../$(echo $BRANCH | tr '/' '-')}"
        if git show-ref --verify --quiet "refs/heads/$BRANCH"; then
            git worktree add "$DIR" "$BRANCH"
        else
            git worktree add -b "$BRANCH" "$DIR"
        fi
        echo "Created worktree at: $DIR"
        ;;
    remove)
        git worktree remove "$2"
        ;;
    list)
        git worktree list
        ;;
    *)
        echo "Usage: $0 {add|remove|list} [branch] [directory]"
        exit 1
        ;;
esac

3. Git Bisect

Basic Bisect:

# Start bisect
git bisect start

# Mark current version as bad
git bisect bad

# Mark known good commit
git bisect good v1.0.0

# Git checks out a commit - test it
# If bad:
git bisect bad
# If good:
git bisect good

# Continue until found
# Git will show: "abc123 is the first bad commit"

# End bisect
git bisect reset

Automated Bisect:

# Create test script
cat > test-bug.sh << 'EOF'
#!/bin/bash
# Return 0 if good, non-zero if bad
npm test -- --grep "specific test"
EOF
chmod +x test-bug.sh

# Run automated bisect
git bisect start
git bisect bad HEAD
git bisect good v1.0.0
git bisect run ./test-bug.sh

# Git will find the bad commit automatically
git bisect reset

Bisect with Skip:

# If commit can't be tested (won't build)
git bisect skip

# Skip range of commits
git bisect skip abc123..def456

Bisect Log and Replay:

# Save bisect session
git bisect log > bisect.log

# Replay session
git bisect replay bisect.log

4. Git Rerere (Reuse Recorded Resolution)

Enable Rerere:

# Enable globally
git config --global rerere.enabled true

# Check status
git config --get rerere.enabled

Using Rerere:

# When you resolve a conflict, git records the resolution
git merge feature-branch
# Resolve conflicts...
git add .
git commit

# Next time same conflict occurs, git auto-applies resolution
git merge another-branch
# "Resolved 'file.txt' using previous resolution."

# If auto-resolution is wrong, forget it
git rerere forget path/to/file

Rerere Management:

# View recorded resolutions
ls .git/rr-cache/

# Clean old resolutions
git rerere gc

# Show diff of recorded resolution
git rerere diff

5. Git Reflog

Basic Reflog:

# Show reflog
git reflog

# Show reflog with dates
git reflog --date=relative

# Show reflog for specific ref
git reflog show feature-branch

# Output
# abc123 HEAD@{0}: commit: Latest commit
# def456 HEAD@{1}: checkout: moving from main to feature
# ghi789 HEAD@{2}: commit: Previous commit

Recovery with Reflog:

# Recover deleted branch
git reflog
# Find last commit of deleted branch: abc123
git checkout -b recovered-branch abc123

# Undo hard reset
git reflog
# Find state before reset: HEAD@{2}
git reset --hard HEAD@{2}

# Recover lost stash
git fsck --unreachable | grep commit
git show <commit-hash>
git stash apply <commit-hash>

# Recover from bad rebase
git reflog
# Find pre-rebase state: HEAD@{5}
git reset --hard HEAD@{5}

Reflog Expiration:

# Check expiration settings
git config --get gc.reflogexpire  # Default: 90 days
git config --get gc.reflogexpireunreachable  # Default: 30 days

# Extend reflog retention
git config --global gc.reflogexpire 180.days

6. Git Hooks

Available Hooks:

client-side:
  pre-commit      # Before commit message prompt
  prepare-commit-msg  # Edit default message
  commit-msg      # Validate commit message
  post-commit     # After commit completes
  pre-push        # Before push

server-side:
  pre-receive     # Before accepting push
  update          # Per-branch check
  post-receive    # After push completes

Pre-commit Hook Example:

#!/bin/bash
# .git/hooks/pre-commit
# ABOUTME: Pre-commit hook for code quality
# ABOUTME: Runs linting and tests before commit

set -e

echo "Running pre-commit checks..."

# Check for debug statements
if git diff --cached --name-only | xargs grep -l 'console.log\|debugger\|binding.pry' 2>/dev/null; then
    echo "ERROR: Debug statements found. Remove before committing."
    exit 1
fi

# Run linter
if [ -f "package.json" ] && grep -q '"lint"' package.json; then
    echo "Running linter..."
    npm run lint --quiet || exit 1
fi

# Run tests
if [ -f "package.json" ] && grep -q '"test"' package.json; then
    echo "Running tests..."
    npm test --quiet || exit 1
fi

echo "Pre-commit checks passed!"

Commit-msg Hook Example:

#!/bin/bash
# .git/hooks/commit-msg
# ABOUTME: Validates commit message format
# ABOUTME: Enforces conventional commits

COMMIT_MSG_FILE="$1"
COMMIT_MSG=$(cat "$COMMIT_MSG_FILE")

# Conventional commit pattern
PATTERN="^(feat|fix|docs|style|refactor|test|chore|perf|ci|build|revert)(\(.+\))?: .{1,50}"

if ! echo "$COMMIT_MSG" | grep -qE "$PATTERN"; then
    echo "ERROR: Invalid commit message format."
    echo ""
    echo "Expected format: <type>(<scope>): <subject>"
    echo "Types: feat, fix, docs, style, refactor, test, chore, perf, ci, build, revert"
    echo ""
    echo "Examples:"
    echo "  feat(auth): add login functionality"
    echo "  fix(api): handle null response"
    echo "  docs: update README"
    exit 1
fi

Pre-push Hook Example:

#!/bin/bash
# .git/hooks/pre-push
# ABOUTME: Pre-push hook for safety checks
# ABOUTME: Prevents pushing to protected branches

BRANCH=$(git rev-parse --abbrev-ref HEAD)
PROTECTED_BRANCHES="^(main|master|production)$"

if echo "$BRANCH" | grep -qE "$PROTECTED_BRANCHES"; then
    echo "ERROR: Direct push to $BRANCH is not allowed."
    echo "Please create a pull request instead."
    exit 1
fi

# Run full test suite before push
echo "Running tests before push..."
npm test || exit 1

echo "Pre-push checks passed!"

Using pre-commit Framework:

# .pre-commit-config.yaml
repos:
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v4.5.0
    hooks:
      - id: trailing-whitespace
      - id: end-of-file-fixer
      - id: check-yaml
      - id: check-json
      - id: check-merge-conflict
      - id: detect-private-key

  - repo: https://github.com/psf/black
    rev: 24.1.0
    hooks:
      - id: black

  - repo: https://github.com/pycqa/flake8
    rev: 7.0.0
    hooks:
      - id: flake8

  - repo: local
    hooks:
      - id: run-tests
        name: Run tests
        entry: npm test
        language: system
        pass_filenames: false
        always_run: true

Install pre-commit hooks:

# Install pre-commit
pip install pre-commit

# Install hooks
pre-commit install

# Install commit-msg hook
pre-commit install --hook-type commit-msg

# Run manually
pre-commit run --all-files

7. Git Aliases

Useful Aliases:

# Add to ~/.gitconfig
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.st status
git config --global alias.unstage 'reset HEAD --'
git config --global alias.last 'log -1 HEAD'
git config --global alias.visual '!gitk'

Advanced Aliases:

# ~/.gitconfig
[alias]
    # Status
    st = status -sb
    ss = status

    # Branch operations
    br = branch
    bra = branch -a
    brd = branch -d
    brD = branch -D

    # Checkout
    co = checkout
    cob = checkout -b
    com = checkout main

    # Commit
    ci = commit
    cia = commit --amend
    ciane = commit --amend --no-edit
    wip = !git add -A && git commit -m 'WIP'

    # Diff
    df = diff
    dfs = diff --staged
    dfw = diff --word-diff

    # Log
    lg = log --graph --oneline --decorate -20
    lga = log --graph --oneline --decorate --all
    ll = log --pretty=format:'%C(yellow)%h%C(reset) %s %C(blue)<%an>%C(reset) %C(green)(%cr)%C(reset)' -20
    hist = log --pretty=format:'%h %ad | %s%d [%an]' --graph --date=short

    # Stash
    sl = stash list
    sp = stash pop
    ss = stash save
    sd = stash drop

    # Remote
    pu = push
    puf = push --force-with-lease
    pl = pull
    plr = pull --rebase
    fe = fetch --all --prune

    # Rebase
    rb = rebase
    rbi = rebase -i
    rbc = rebase --continue
    rba = rebase --abort

    # Reset
    undo = reset --soft HEAD~1
    nuke = reset --hard HEAD

    # Clean
    clean-branches = !git branch --merged | grep -v '*' | xargs -n 1 git branch -d

    # Find
    find = !git ls-files | grep -i
    grep = grep -Ii

    # Utility
    aliases = !git config --get-regexp '^alias\\.' | sed 's/alias\\.\\([^ ]*\\) \\(.*\\)/\\1\\\t => \\2/' | sort
    contributors = shortlog -sn

8. Submodules

Basic Submodule Operations:

# Add submodule
git submodule add https://github.com/user/repo libs/repo

# Clone with submodules
git clone --recurse-submodules https://github.com/user/main-repo

# Initialize submodules after clone
git submodule init
git submodule update

# Or combined
git submodule update --init --recursive

# Update submodule to latest
cd libs/repo
git checkout main
git pull
cd ../..
git add libs/repo
git commit -m "Update submodule"

# Update all submodules
git submodule update --remote

Submodule Configuration:

# Track specific branch
git config -f .gitmodules submodule.libs/repo.branch main

# Shallow clone submodules
git config -f .gitmodules submodule.libs/repo.shallow true

# Update strategy
git submodule update --remote --merge  # Merge changes
git submodule update --remote --rebase # Rebase changes

Submodule Workflow Script:

#!/bin/bash
# scripts/submodule-sync.sh
# ABOUTME: Synchronize all submodules
# ABOUTME: Updates submodules to latest remote commits

set -e

echo "Synchronizing submodules..."

# Initialize any new submodules
git submodule init

# Update all submodules to tracked branch
git submodule update --remote --merge

# Show status
git submodule status

echo "Submodules synchronized!"

9. Monorepo Patterns

Sparse Checkout:

# Enable sparse checkout
git sparse-checkout init

# Set patterns
git sparse-checkout set packages/app packages/shared

# Add more patterns
git sparse-checkout add docs

# Disable sparse checkout
git sparse-checkout disable

Working with Monorepos:

# Clone specific directory only
git clone --filter=blob:none --sparse https://github.com/user/monorepo
cd monorepo
git sparse-checkout set packages/my-package

# Shallow clone for faster checkout
git clone --depth 1 --filter=blob:none --sparse https://github.com/user/monorepo

# Partial clone (fetch objects on demand)
git clone --filter=blob:none https://github.com/user/monorepo

Monorepo Commit Strategy:

# Commit message with scope
git commit -m "feat(package-name): add feature X"

# Using conventional commits
feat(api): add new endpoint
fix(web): resolve routing issue
chore(deps): update dependencies
docs(shared): improve API documentation

Integration Examples

1. Complete.gitconfig

# ~/.gitconfig

[user]
    name = Your Name
    email = your.email@example.com

[core]
    editor = vim
    autocrlf = input
    pager = delta

[init]
    defaultBranch = main

[pull]
    rebase = true

[push]
    autoSetupRemote = true
    default = current

[fetch]
    prune = true
    pruneTags = true

[merge]
    conflictStyle = diff3
    ff = false

[rebase]
    autosquash = true
    autostash = true

[rerere]
    enabled = true

[diff]
    algorithm = histogram
    colorMoved = default

[status]
    showUntrackedFiles = all

[credential]
    helper = cache --timeout=3600

[alias]
    # Core aliases
    st = status -sb
    co = checkout
    br = branch
    ci = commit
    lg = log --graph --oneline --decorate -20

    # Workflow aliases
    undo = reset --soft HEAD~1
    wip = !git add -A && git commit -m 'WIP'
    sync = !git fetch --all --prune && git pull --rebase

    # Branch cleanup
    cleanup = !git branch --merged main | grep -v '^[ *]*main$' | xargs git branch -d

[delta]
    navigate = true
    side-by-side = true
    line-numbers = true

[interactive]
    diffFilter = delta --color-only

2. GitHub Workflow with Hooks

# .github/workflows/pr-check.yml
name: PR Checks

on:
  pull_request:
    branches: [main]

jobs:
  validate:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Validate commit messages
        run: |
          COMMITS=$(git log --format="%s" origin/main..HEAD)
          PATTERN="^(feat|fix|docs|style|refactor|test|chore)(\(.+\))?: .+"
          while IFS= read -r commit; do
            if ! echo "$commit" | grep -qE "$PATTERN"; then
              echo "Invalid commit message: $commit"
              exit 1
            fi
          done <<< "$COMMITS"

      - name: Check for merge commits
        run: |
          MERGE_COMMITS=$(git log --merges origin/main..HEAD --oneline)
          if [ -n "$MERGE_COMMITS" ]; then
            echo "Merge commits found. Please rebase instead."
            echo "$MERGE_COMMITS"
            exit 1
          fi

      - name: Run tests
        run: npm test

3. Git Flow Helper Functions

# Add to ~/.bashrc

# Start feature
gf-start() {
    local feature="$1"
    git checkout main
    git pull
    git checkout -b "feature/$feature"
}

# Finish feature
gf-finish() {
    local branch=$(git rev-parse --abbrev-ref HEAD)
    git checkout main
    git pull
    git merge --no-ff "$branch"
    git branch -d "$branch"
}

# Start hotfix
gh-start() {
    local hotfix="$1"
    git checkout main
    git pull
    git checkout -b "hotfix/$hotfix"
}

# Sync branch with main
gsync() {
    local branch=$(git rev-parse --abbrev-ref HEAD)
    git fetch origin main:main
    git rebase main
}

Best Practices

1. Commit History

# Write good commit messages
git commit -m "feat(auth): add OAuth2 support

- Add Google OAuth provider
- Implement token refresh logic
- Add user profile sync

Closes #123"

# Keep commits atomic
# One logical change per commit

# Use conventional commits
# feat: new feature
# fix: bug fix
# docs: documentation
# style: formatting
# refactor: code restructure
# test: add tests
# chore: maintenance

2. Branch Strategy

# Feature branches from main
git checkout -b feature/add-auth main

# Hotfix branches from main
git checkout -b hotfix/fix-login main

# Keep branches short-lived
# Merge frequently

# Delete merged branches
git branch -d feature/add-auth

3. Rebase vs Merge

# Use rebase for:
# - Cleaning up local commits
# - Updating feature branch from main
git rebase main

# Use merge for:
# - Integrating feature into main
# - Preserving branch history
git merge --no-ff feature/add-auth

Troubleshooting

Common Issues

Accidental commit to wrong branch:

# Move commit to new branch
git branch new-branch
git reset --hard HEAD~1
git checkout new-branch

Undo merge:

# If not pushed
git reset --hard HEAD~1

# If pushed
git revert -m 1 <merge-commit>

Lost changes after checkout:

# Check reflog
git reflog

# Recover from reflog
git checkout HEAD@{2}

Resolve rebase conflicts:

# During rebase conflict
git status
# Edit conflicted files
git add <resolved-files>
git rebase --continue

# Abort if needed
git rebase --abort

Clean up after failed rebase:

git rebase --abort
# Or
git reflog
git reset --hard HEAD@{n}

Version History

  • 1.0.0 (2026-01-17): Initial release

- Interactive rebase patterns - Git worktrees for parallel development - Bisect for bug hunting - Rerere and reflog for recovery - Hooks and custom commands - Submodules and monorepo patterns


Use this skill to master advanced git workflows and maintain clean, professional version control!

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

04

需要参考平台分布和安装热度时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

补充不同宿主或平台的使用分布数据

能力 5

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Claude Code

29.01%
按下载量换算46

windsurf

25.23%
按下载量换算40

trae

19.16%
按下载量换算30

OpenCode

12.21%
按下载量换算19

Cursor

7.56%
按下载量换算12

Codex

3.69%
按下载量换算6

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

可疑

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。来源安全扫描存在 warning/failed 结果,不能写成本站确认安全。

来源信息

继续浏览同类 Skills