Aide-mémoire des commandes Git

Référence rapide des commandes Git courantes, couvrant les bases, les branches, les dépôts distants, l'annulation et plus. 100 % gratuit, exécuté localement dans votre navigateur — rien n'est téléversé vers nos serveurs.

Basic

git init— Initialize a new repositoryCliquez pour copier
git clone <url>— Clone a remote repositoryCliquez pour copier
git status— Show working tree statusCliquez pour copier
git add <file>— Stage file(s) for commitCliquez pour copier
git add .— Stage all changesCliquez pour copier
git commit -m "msg"— Commit staged changesCliquez pour copier
git diff— Show unstaged changesCliquez pour copier
git diff --staged— Show staged changesCliquez pour copier

Branch

git branch— List local branchesCliquez pour copier
git branch <name>— Create a new branchCliquez pour copier
git checkout <branch>— Switch to branchCliquez pour copier
git checkout -b <name>— Create & switch to branchCliquez pour copier
git switch <branch>— Switch to branch (new)Cliquez pour copier
git switch -c <name>— Create & switch (new)Cliquez pour copier
git merge <branch>— Merge branch into currentCliquez pour copier
git branch -d <name>— Delete a branchCliquez pour copier
git branch -m <old> <new>— Rename a branchCliquez pour copier

Remote

git remote -v— List remote repositoriesCliquez pour copier
git remote add <name> <url>— Add a remoteCliquez pour copier
git fetch— Fetch from remoteCliquez pour copier
git pull— Fetch & mergeCliquez pour copier
git push— Push to remoteCliquez pour copier
git push -u origin <branch>— Push & set upstreamCliquez pour copier
git remote remove <name>— Remove a remoteCliquez pour copier

Undo/Reset

git reset HEAD <file>— Unstage a fileCliquez pour copier
git checkout -- <file>— Discard working changesCliquez pour copier
git restore <file>— Discard working changes (new)Cliquez pour copier
git reset --soft HEAD~1— Undo last commit, keep stagedCliquez pour copier
git reset --mixed HEAD~1— Undo last commit, keep unstagedCliquez pour copier
git reset --hard HEAD~1— Undo last commit, discard allCliquez pour copier
git revert <commit>— Create undo commitCliquez pour copier

Stash

git stash— Stash current changesCliquez pour copier
git stash list— List stashesCliquez pour copier
git stash pop— Apply & remove latest stashCliquez pour copier
git stash apply— Apply latest stashCliquez pour copier
git stash drop— Remove latest stashCliquez pour copier
git stash push -m "msg"— Stash with a messageCliquez pour copier

Log

git log— Show commit historyCliquez pour copier
git log --oneline— Compact commit historyCliquez pour copier
git log --graph— Graph of branchesCliquez pour copier
git log -n <count>— Show last N commitsCliquez pour copier
git show <commit>— Show commit detailsCliquez pour copier
git blame <file>— Line-by-line historyCliquez pour copier

Tag

git tag— List tagsCliquez pour copier
git tag <name>— Create lightweight tagCliquez pour copier
git tag -a <name> -m "msg"— Create annotated tagCliquez pour copier
git tag -d <name>— Delete a tagCliquez pour copier
git push origin --tags— Push tags to remoteCliquez pour copier