You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
git config --global user.name "Ton Nom"# définir ton nom
git config --global user.email "email@..."# définir ton email
git config --list # voir la configuration
📁 Créer / Cloner
git init # initialiser un repo
git clone <url># cloner un repo existant
git clone <url> mon-dossier # cloner dans un dossier spécifique
📊 État & Différences
git status # état des fichiers
git diff # modifications non stagées
git diff --staged # modifications stagées
git log --oneline # historique court
git log --oneline --graph --all # historique avec branches
➕ Staging & Commit
git add fichier.py # ajouter un fichier
git add .# ajouter tout
git add *.py # ajouter tous les .py
git restore --staged fichier.py # annuler un git add
git commit -m "message"# commit
git commit --amend -m "nouveau message"# modifier le dernier commit
🔄 Remote (GitHub)
git remote add origin <url># connecter à GitHub
git remote -v # voir les remotes
git push -u origin main # premier push
git push # push suivants
git pull # pull (fetch + merge)
git fetch # récupérer sans fusionner
🌿 Branches
git branch # lister les branches
git branch ma-branche # créer une branche
git checkout ma-branche # aller sur une branche
git checkout -b ma-branche # créer + aller (raccourci)
git switch ma-branche # (nouvelle syntaxe)
git switch -c ma-branche # créer + aller (nouvelle syntaxe)
git merge ma-branche # fusionner dans la branche actuelle
git branch -d ma-branche # supprimer une branche (fusionnée)
git branch -D ma-branche # forcer la suppression
git push origin --delete ma-branche # supprimer sur GitHub
↩️ Annuler des changements
git restore fichier.py # annuler modifications (non stagées)
git restore .# annuler toutes les modifications
git restore --staged fichier.py # déstaguer un fichier
git reset --soft HEAD~1 # annuler dernier commit (garde les modifs)
git reset --hard HEAD~1 # annuler dernier commit (⚠️ supprime les modifs)
git revert <hash># créer un commit qui annule un autre (safe)
🗃️ Stash (mettre de côté temporairement)
git stash # mettre de côté les modifications
git stash list # voir les stash
git stash pop # récupérer le dernier stash
git stash drop # supprimer le dernier stash
🏷️ Tags
git tag v1.0 # créer un tag
git tag # lister les tags
git push origin v1.0 # pousser un tag sur GitHub
🔍 Recherche
git log --oneline --grep="mot"# chercher dans les messages de commit
git blame fichier.py # voir qui a modifié chaque ligne
git show <hash># voir un commit spécifique
🚨 Commandes d'urgence
# "J'ai tout cassé, je veux revenir à l'état du dernier commit"
git restore .# "J'ai commité sur main au lieu de ma branche"
git branch ma-branche # crée la branche avec le commit
git reset --soft HEAD~1 # annule le commit sur main
git checkout ma-branche # va sur la branche# "Je veux voir un ancien commit sans rien casser"
git checkout <hash># détached HEAD (exploration)
git checkout main # retour à la normale# "J'ai pushé quelque chose par erreur"
git revert <hash># crée un commit inverse (recommandé)
git push # pousse l'annulation