Workflows Git avancés

VérifiéPrudence

Maîtrisez les techniques Git avancées pour maintenir un historique propre, collaborer efficacement et récupérer de toute situation.

Spar Skills Guide Bot
DeveloppementAvancé
23/07/2026
Claude CodeCursorWindsurfCopilotCodex
#git#version-control#rebase#bisect#reflog

Recommandé pour

Synthèse automatique

Cette compétence présente des techniques Git avancées — rebase interactif, cherry-pick, bisect, worktrees et reflog — pour assainir l'historique et récupérer des commits perdus.

Points forts

  • Couvre les opérations essentielles du rebase interactif avec une explication claire de chaque action.
  • Fournit des exemples concrets pour le cherry-pick, le bisect automatisé, les worktrees et la récupération via reflog.
  • Inclut un workflow pratique de nettoyage de branche avant une pull request, avec push sécurisé via --force-with-lease.

Limites

  • Sert de guide de référence : aucun script de vérification ni test automatisé n'est fourni au-delà de l'exemple de bisect.
  • La réécriture d'historique et le force push restent risqués et nécessitent une coordination avec l'équipe.
  • Suppose une bonne maîtrise des bases de Git, sans rappeler les commandes fondamentales.
Quand l'utiliser

À utiliser lorsqu'il faut nettoyer un historique de commits, appliquer des commits ciblés, localiser une régression, gérer plusieurs branches en parallèle ou restaurer du travail perdu.

Quand l'éviter

À éviter pour de simples opérations Git de base ou pour des tâches sans rapport avec Git.

Analyse de sécurité

Prudence
Score qualité78/100

The content is a legitimate advanced-Git guide with no exfiltration, obfuscation, remote code download, or safety-disabling behavior. However, it is command-heavy and includes history-rewriting and hard-reset operations, so an agent applying it needs bash and should treat destructive commands carefully; this warrants caution rather than a clean safe rating.

Points d'attention
  • •The skill is essentially a shell-command playbook with no declared allowed-tools: it describes many `git` operations that an agent would need bash to execute.
  • •Several instructions are destructive by nature (`git reset --hard`, history rewriting, `git push --force-with-lease`). The text mitigates these with backup branches and lease-based force-push guidance, but blindly following them can still discard local work or rewrite shared history.
  • •Contains destructive Git commands such as `git reset --hard` and `git push --force-with-lease`; blind execution could discard local work or rewrite shared history.
  • •References a helper script (`scripts/git-clean-branches.sh`) whose contents are not shown, so its behavior cannot be audited from SKILL.md.
Comment cette analyse est faite

Exemples

Clean a feature branch
Squash and reword my last five commits on feature/user-auth before I open a PR. Use interactive rebase and then push safely with --force-with-lease.
Find a regression with bisect
Find the commit that introduced the failing test in our main branch using git bisect, with test.sh as the automated good/bad check.
Recover work and use a worktree
I accidentally deleted my branch. Recover it from the reflog and set up a worktree so I can work on an urgent hotfix without stashing my current changes.

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, co..." risk: unknown source: community date_added: "2026-02-27"

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.
  • If detailed examples are required, open resources/implementation-playbook.md.

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

Du fichier au premier essai

Le téléchargement contient exactement le contenu affiché sur cette fiche. Cette copie peut différer de la dernière version du dépôt source.

Consulter la source et ses fichiers annexes

Ce téléchargement contient uniquement SKILL.md. Les scripts, références, modèles et dépendances éventuels ne sont pas inclus. Récupérez les fichiers nécessaires depuis la source en conservant leur arborescence avant de poursuivre.

1. Télécharger le fichier

Télécharger SKILL.md

Depuis la racine d’un projet de test, enregistrez le fichier sous .skill-downloads/advanced-git-workflows-mrx3xyhz/SKILL.md, ou utilisez la commande suivante. Ce dossier sert à examiner la skill avant son installation.

Commande pour macOS/Linux ou WSL : un shell POSIX et curl sont nécessaires. Sous Windows sans WSL, utilisez le bouton de téléchargement et créez le dossier manuellement.

mkdir -p '.skill-downloads/advanced-git-workflows-mrx3xyhz' && curl --fail --show-error --location 'https://skills-guides.com/api/skills/advanced-git-workflows-mrx3xyhz/download' --output '.skill-downloads/advanced-git-workflows-mrx3xyhz/SKILL.md.part' && mv '.skill-downloads/advanced-git-workflows-mrx3xyhz/SKILL.md.part' '.skill-downloads/advanced-git-workflows-mrx3xyhz/SKILL.md'

2. Vérifier les prérequis

Lisez SKILL.md avant de l’utiliser. Si le fichier cite des scripts ou services externes, examinez-les et préparez les accès nécessaires dans votre environnement de test.

Aucune section de prérequis reconnue dans ce fichier. Cela ne signifie pas qu’il est autonome : les bibliothèques, outils et accès peuvent être cités ailleurs dans le contenu ou dans le dépôt source.

Les plateformes de la fiche sont des indications du catalogue. Les chemins ci-dessous suivent la documentation des outils ; ils ne prouvent pas que cette skill y a été exécutée. Aucune version minimale de ces outils n’est attestée pour cette fiche.

3. Charger la skill

Après vérification, copiez le dossier complet dans le projet avec l’une des commandes ci-dessous, puis ouvrez une nouvelle session de l’outil. La commande s’arrête si un dossier du même nom existe déjà : comparez les fichiers avant de le remplacer.

Claude Code
test -f '.skill-downloads/advanced-git-workflows-mrx3xyhz/SKILL.md' && test -s '.skill-downloads/advanced-git-workflows-mrx3xyhz/SKILL.md' && mkdir -p '.claude/skills' && test ! -e '.claude/skills/git-advanced-workflows' && cp -R '.skill-downloads/advanced-git-workflows-mrx3xyhz' '.claude/skills/git-advanced-workflows'

Cursor
test -f '.skill-downloads/advanced-git-workflows-mrx3xyhz/SKILL.md' && test -s '.skill-downloads/advanced-git-workflows-mrx3xyhz/SKILL.md' && mkdir -p '.cursor/skills' && test ! -e '.cursor/skills/git-advanced-workflows' && cp -R '.skill-downloads/advanced-git-workflows-mrx3xyhz' '.cursor/skills/git-advanced-workflows'

Codex
test -f '.skill-downloads/advanced-git-workflows-mrx3xyhz/SKILL.md' && test -s '.skill-downloads/advanced-git-workflows-mrx3xyhz/SKILL.md' && mkdir -p '.agents/skills' && test ! -e '.agents/skills/git-advanced-workflows' && cp -R '.skill-downloads/advanced-git-workflows-mrx3xyhz' '.agents/skills/git-advanced-workflows'

OpenSkills

OpenSkills doit déjà être installé. La procédure locale install/read est contrôlée avec OpenSkills 1.5.0, qui exige Node.js ≥ 20.6.0. Aucun slug du catalogue n’est résolu automatiquement.

Installation officielle d’OpenSkills
openskills install './.skill-downloads/advanced-git-workflows-mrx3xyhz'

openskills read 'advanced-git-workflows-mrx3xyhz'

La lecture doit afficher le contenu du fichier installé et son dossier de base. Elle ne lance ni la skill ni ses dépendances.

Pour un agent qui lit AGENTS.md, synchronisez ensuite l’index. Cette commande modifie AGENTS.md : relisez le diff avant de l’utiliser.

openskills sync

Mode manuel ou autre outil : joignez SKILL.md à une conversation, ou ouvrez-le dans un agent capable de lire les fichiers. Ajoutez les ressources annexes nécessaires. Il n’existe pas de dossier universel reconnu par tous les outils.

4. Faire un premier essai

Utilisez une entrée courte et fictive : un endpoint d’API, un petit document ou un brief d’interface. Dans une nouvelle conversation, joignez le fichier ou donnez son chemin à l’agent, puis adaptez cette demande :

Lis .skill-downloads/advanced-git-workflows-mrx3xyhz/SKILL.md et applique ses instructions à cet exemple : [décrire une entrée de test]. Indique les fichiers, dépendances ou accès qui manquent. Produis le résultat demandé par la skill sans inventer de données ni exécuter de script non examiné.

Résultat attendu : une sortie correspondant aux instructions de la skill, ou une liste précise des prérequis manquants. Une simple confirmation de lecture ne valide pas le premier usage. Si une ressource externe est indisponible, ce parcours reste à tester.

Skills similaires