Git - Contrôle de version

VérifiéSûr

Maîtrise complète de Git pour le contrôle de version, les branches, les fusions et les workflows collaboratifs. Couvre les commandes essentielles et les opérations avancées.

Spar Skills Guide Bot
DeveloppementIntermédiaire
4002/06/2026
Claude CodeCursorWindsurfCopilotCodex
#git#version-control#branching#collaboration

Recommandé pour

Notre avis

Ce skill fournit une assistance experte pour les opérations Git, incluant les commits, branches, fusions, rebasages et résolution de conflits.

Points forts

  • Couvre toutes les opérations courantes de Git, des bases aux avancées
  • Explications claires avec des commandes concrètes
  • Inclut des workflows typiques (feature branch, hotfix)

Limites

  • Ne remplace pas une compréhension approfondie de Git
  • Peut être limité pour des scénarios très complexes ou spécifiques à un dépôt
Quand l'utiliser

Utilisez ce skill pour obtenir des conseils précis sur des commandes Git, des workflows ou résoudre des problèmes de versioning.

Quand l'éviter

Évitez de l'utiliser si vous avez besoin d'une intégration poussée avec des API Git spécifiques ou une automatisation avancée non couverte ici.

Analyse de sécurité

Sûr
Score qualité85/100

The skill provides a static reference of git commands and workflows. It does not instruct execution of any commands, nor does it contain scripts, URLs, or data exfiltration mechanisms. While git operations can be destructive (e.g., force push, hard reset), the skill is purely educational and does not automate risky actions.

Aucun point d'attention détecté

Exemples

Undo last commit
How do I undo the last commit but keep the changes?
Resolve merge conflicts
I'm in the middle of a merge with conflicts. Can you help me resolve them step by step?
Feature branch workflow
Show me the complete workflow for creating a feature branch, working on it, and merging it back into main.

name: Git description: Expert guidance for Git version control operations including commits, branches, merging, rebasing, conflict resolution, and Git workflows. Use this when working with Git repositories, version control, or collaborative development.

Git

Expert assistance with Git version control and collaborative workflows.

Essential Commands

Repository Setup

  • git init - Initialize new repository
  • git clone <url> - Clone remote repository
  • git remote add origin <url> - Add remote
  • git remote -v - List remotes

Daily Workflow

  • git status - Check working tree status
  • git add . - Stage all changes
  • git add -p - Interactive staging
  • git commit -m "message" - Commit with message
  • git commit --amend - Amend last commit
  • git pull - Fetch and merge from remote
  • git push - Push commits to remote

Branch Management

  • git branch - List local branches
  • git branch -a - List all branches (including remote)
  • git branch <name> - Create new branch
  • git checkout <branch> - Switch to branch
  • git checkout -b <name> - Create and switch to new branch
  • git branch -d <name> - Delete branch (safe)
  • git branch -D <name> - Force delete branch
  • git push origin --delete <branch> - Delete remote branch

Viewing History

  • git log - View commit history
  • git log --oneline --graph - Compact graphical history
  • git log --author="name" - Filter by author
  • git show <commit> - Show commit details
  • git diff - Show unstaged changes
  • git diff --staged - Show staged changes
  • git diff <branch1>..<branch2> - Compare branches

Undoing Changes

  • git restore <file> - Discard working changes
  • git restore --staged <file> - Unstage file
  • git reset HEAD~1 - Undo last commit (keep changes)
  • git reset --hard HEAD~1 - Undo last commit (discard changes)
  • git revert <commit> - Create new commit that undoes changes
  • git clean -fd - Remove untracked files

Stashing

  • git stash - Stash current changes
  • git stash list - List stashes
  • git stash pop - Apply and remove last stash
  • git stash apply - Apply last stash (keep in list)
  • git stash drop - Delete last stash

Advanced Operations

Rebasing

# Rebase current branch onto main
git rebase main

# Interactive rebase (squash, reorder, edit commits)
git rebase -i HEAD~3

# Continue after resolving conflicts
git rebase --continue

# Abort rebase
git rebase --abort

Cherry-picking

# Apply specific commit to current branch
git cherry-pick <commit-hash>

# Cherry-pick without committing
git cherry-pick -n <commit-hash>

Merging

# Merge branch into current
git merge <branch>

# Merge without fast-forward (create merge commit)
git merge --no-ff <branch>

# Abort merge
git merge --abort

Conflict Resolution

# Show conflicts
git status

# After resolving conflicts in files
git add <resolved-file>
git commit

# Use theirs/ours for entire file
git checkout --theirs <file>
git checkout --ours <file>

Git Workflows

Feature Branch Workflow

# Create feature branch
git checkout -b feature/new-feature

# Work and commit
git add .
git commit -m "Add new feature"

# Update from main
git checkout main
git pull
git checkout feature/new-feature
git rebase main

# Push feature branch
git push -u origin feature/new-feature

Hotfix Workflow

# Create hotfix from main
git checkout main
git pull
git checkout -b hotfix/critical-fix

# Fix and commit
git commit -am "Fix critical bug"

# Merge back to main
git checkout main
git merge hotfix/critical-fix
git push

# Clean up
git branch -d hotfix/critical-fix

Configuration

User Setup

git config --global user.name "Your Name"
git config --global user.email "your@email.com"

Useful Aliases

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.lg "log --oneline --graph --all"

Editor

git config --global core.editor "vim"

Best Practices

  1. Commit Messages: Use clear, descriptive messages following conventional commits
  2. Small Commits: Make atomic commits that do one thing
  3. Pull Before Push: Always pull latest changes before pushing
  4. Branch Naming: Use descriptive names like feature/, bugfix/, hotfix/
  5. Never Force Push: Avoid git push --force on shared branches
  6. Review Changes: Use git diff before committing
  7. Protect Main: Never commit directly to main/master

Troubleshooting

Undo accidental commit to wrong branch

git reset HEAD~1  # Undo commit, keep changes
git stash         # Stash changes
git checkout <correct-branch>
git stash pop     # Apply changes
git add .
git commit -m "message"

Fix merge conflicts

# View conflicts
git status

# Edit conflicting files (look for <<<<<<, ======, >>>>>>)
# Remove conflict markers and keep desired code

# Mark as resolved
git add <file>
git commit

Recover deleted branch

# Find commit hash
git reflog

# Recreate branch
git checkout -b <branch-name> <commit-hash>
Skills similaires