Commandes Git essentielles pour les commits, branches, fusions, rebase, remotes et plus.
git config --global user.name "Name"Configuration & installationSet global author name
ex. git config --global user.name "Jane Doe"
git config --global user.email "email"Configuration & installationSet global author email
ex. git config --global user.email "[email protected]"
git config --listConfiguration & installationList all configuration settings
git config --global core.editor "code"Configuration & installationSet VS Code as default editor
git config --global alias.<alias> <cmd>Configuration & installationCreate a command alias
ex. git config --global alias.st status
git initConfiguration & installationInitialize a new local repository
git init <dir>Configuration & installationInitialize a repo in a specific directory
ex. git init my-project
git clone <url>Configuration & installationClone a remote repository
ex. git clone https://github.com/user/repo.git
git clone <url> <dir>Configuration & installationClone into a specific folder
ex. git clone https://github.com/user/repo.git my-dir
git statusStaging & basesShow working tree status
git status -sStaging & basesShort/compact status output
git add <file>Staging & basesStage a specific file
ex. git add README.md
git add .Staging & basesStage all changes in current directory
git add -pStaging & basesInteractively stage hunks of changes
git commit -m "msg"Staging & basesCommit staged changes with a message
ex. git commit -m "feat: add login page"
git commit -am "msg"Staging & basesStage tracked files and commit in one step
git commit --amenddestructifStaging & basesModify the most recent commit (message or content)
git diffStaging & basesShow unstaged changes
git diff --stagedStaging & basesShow staged changes (vs last commit)
git diff <branch1>..<branch2>Staging & basesCompare two branches
ex. git diff main..feature
git rm <file>Staging & basesRemove a file from working tree and index
ex. git rm old-file.txt
git rm --cached <file>Staging & basesUntrack a file without deleting it
ex. git rm --cached secret.txt
git mv <old> <new>Staging & basesMove or rename a tracked file
ex. git mv old.js new.js
git branchBranches et fusionsList local branches
git branch -aBranches et fusionsList all branches (local + remote)
git branch <name>Branches et fusionsCreate a new branch
ex. git branch feature/auth
git checkout <branch>Branches et fusionsSwitch to an existing branch
ex. git checkout main
git checkout -b <branch>Branches et fusionsCreate and switch to a new branch
ex. git checkout -b feature/auth
git switch <branch>Branches et fusionsSwitch branches (modern syntax)
ex. git switch main
git switch -c <branch>Branches et fusionsCreate and switch (modern syntax)
ex. git switch -c feature/auth
git branch -d <branch>Branches et fusionsDelete a merged branch
ex. git branch -d feature/auth
git branch -D <branch>destructifBranches et fusionsForce delete a branch (unmerged too)
ex. git branch -D feature/old
git branch -m <old> <new>Branches et fusionsRename a branch
ex. git branch -m old-name new-name
git merge <branch>Branches et fusionsMerge a branch into current branch
ex. git merge feature/auth
git merge --no-ff <branch>Branches et fusionsMerge with a merge commit (no fast-forward)
git merge --squash <branch>Branches et fusionsSquash all commits from branch into one staged change
git merge --abortBranches et fusionsAbort an in-progress merge
git remote -vOpérations distantesList remote connections with URLs
git remote add <name> <url>Opérations distantesAdd a new remote
ex. git remote add origin https://github.com/user/repo.git
git remote remove <name>Opérations distantesRemove a remote connection
ex. git remote remove origin
git remote rename <old> <new>Opérations distantesRename a remote
ex. git remote rename origin upstream
git fetchOpérations distantesDownload all changes from remote (no merge)
git fetch <remote>Opérations distantesFetch from a specific remote
ex. git fetch origin
git pullOpérations distantesFetch and merge changes from remote
git pull --rebaseOpérations distantesFetch and rebase onto remote branch
git push <remote> <branch>Opérations distantesPush branch to remote
ex. git push origin main
git push -u origin <branch>Opérations distantesPush and set upstream tracking
ex. git push -u origin feature/auth
git push --force-with-leasedestructifOpérations distantesSafe force push (fails if others pushed)
git push --tagsOpérations distantesPush all tags to remote
git push origin --delete <branch>destructifOpérations distantesDelete a remote branch
ex. git push origin --delete feature/old
git restore <file>destructifAnnuler des modificationsDiscard changes in working directory
ex. git restore index.html
git restore --staged <file>Annuler des modificationsUnstage a file (keep changes)
ex. git restore --staged index.html
git reset HEAD <file>Annuler des modificationsUnstage a file (older syntax)
ex. git reset HEAD index.html
git reset --soft HEAD~1Annuler des modificationsUndo last commit, keep changes staged
git reset --mixed HEAD~1Annuler des modificationsUndo last commit, unstage changes (default)
git reset --hard HEAD~1destructifAnnuler des modificationsUndo last commit, discard all changes
git reset --hard <commit>destructifAnnuler des modificationsReset to a specific commit, discard everything after
git revert <commit>Annuler des modificationsCreate a new commit that undoes a specific commit
ex. git revert a1b2c3d
git revert HEADAnnuler des modificationsRevert the most recent commit
git clean -fddestructifAnnuler des modificationsRemove untracked files and directories
git clean -nAnnuler des modificationsDry run: show what would be cleaned
git stashRemisageStash current working directory changes
git stash push -m "msg"RemisageStash with a descriptive message
ex. git stash push -m "WIP: auth feature"
git stash listRemisageList all stashes
git stash popRemisageApply most recent stash and remove it
git stash apply stash@{n}RemisageApply a specific stash without removing
ex. git stash apply stash@{0}
git stash drop stash@{n}RemisageDelete a specific stash
ex. git stash drop stash@{0}
git stash cleardestructifRemisageRemove all stashes
git stash branch <branch>RemisageCreate a branch from a stash
ex. git stash branch feature/from-stash
git rebase <branch>Rebase & avancéRebase current branch onto another
ex. git rebase main
git rebase -i HEAD~nRebase & avancéInteractive rebase for last n commits
ex. git rebase -i HEAD~3
git rebase --continueRebase & avancéContinue rebase after resolving conflicts
git rebase --abortRebase & avancéAbort an in-progress rebase
git cherry-pick <commit>Rebase & avancéApply a specific commit to current branch
ex. git cherry-pick a1b2c3d
git cherry-pick <c1>..<c2>Rebase & avancéApply a range of commits
ex. git cherry-pick a1b2c3d..f6e5d4c
git bisect startRebase & avancéStart binary search for a bug
git bisect good <commit>Rebase & avancéMark a commit as good in bisect
git bisect bad <commit>Rebase & avancéMark a commit as bad in bisect
git bisect resetRebase & avancéEnd bisect session
git worktree add <path> <branch>Rebase & avancéCheck out a branch into a separate directory
git logInspection & journalShow commit history
git log --onelineInspection & journalCompact one-line log
git log --oneline --graph --allInspection & journalVisual branch graph in terminal
git log -n <count>Inspection & journalShow last N commits
ex. git log -n 5
git log --author="name"Inspection & journalFilter commits by author
ex. git log --author="Jane Doe"
git log --since="2 weeks ago"Inspection & journalShow commits since a date
git log -p <file>Inspection & journalShow changes to a specific file over time
ex. git log -p README.md
git log --follow <file>Inspection & journalFollow renames of a file in history
git show <commit>Inspection & journalShow details of a specific commit
ex. git show a1b2c3d
git blame <file>Inspection & journalShow who last modified each line
ex. git blame src/app.tsx
git shortlog -snInspection & journalSummarize commits by author
git reflogInspection & journalShow history of HEAD movements (recovery tool)
git grep "pattern"Inspection & journalSearch working directory for a pattern
ex. git grep "TODO"
git tagTagsList all tags
git tag <name>TagsCreate a lightweight tag
ex. git tag v1.0.0
git tag -a <name> -m "msg"TagsCreate an annotated tag
ex. git tag -a v1.0.0 -m "Release v1.0.0"
git tag -a <name> <commit>TagsTag a past commit
ex. git tag -a v0.9.0 a1b2c3d
git show <tag>TagsShow tag metadata and commit
ex. git show v1.0.0
git push origin <tag>TagsPush a specific tag to remote
ex. git push origin v1.0.0
git push origin --tagsTagsPush all tags to remote
git tag -d <tag>TagsDelete a local tag
ex. git tag -d v1.0.0
git push origin --delete <tag>TagsDelete a remote tag
ex. git push origin --delete v1.0.0
git merge combine deux branches en créant un commit de fusion, préservant l'historique complet des deux branches. git rebase déplace les commits d'une branche sur une autre, réécrivant l'historique pour créer un historique de commits linéaire et plus propre. Utilisez merge pour les branches publiques et le travail partagé ; rebase pour nettoyer les branches de fonctionnalités locales avant de les fusionner.
Utilisez git reset --soft HEAD~1 pour annuler le dernier commit tout en gardant les modifications en staging. Utilisez git reset HEAD~1 (ou --mixed) pour désindexer les modifications mais les garder dans le répertoire de travail. Utilisez git reset --hard HEAD~1 pour supprimer définitivement le commit et tous les changements (opération destructive).
git fetch télécharge les modifications depuis le dépôt distant mais ne les fusionne PAS dans votre branche actuelle. Il met à jour vos branches de suivi distant (origin/main). git pull est git fetch + git merge (ou git rebase avec --rebase). Utilisez fetch quand vous voulez inspecter les modifications avant de les intégrer.
Après une fusion/rebase conflictuelle, Git marque les fichiers conflictuels avec les marqueurs '<<<<<<', =======, >>>>>>. Ouvrez chaque fichier conflictuel, choisissez manuellement quels changements conserver, supprimez les marqueurs, puis indexez les fichiers résolus avec git add '<'fichier> et terminez avec git merge --continue ou git commit.