Aide-mémoire des commandes Git

Git suit les changements de vos fichiers sous forme d'une série de commits dans un dépôt. Ces commandes couvrent le flux quotidien : créer un dépôt, enregistrer le travail, brancher, fusionner et partager avec un distant. Gardez cette fiche ouverte pendant l'apprentissage.

Mis à jour:

CommandeÀ quoi ça sert
git initCreate a new, empty Git repository in the current directory.
git cloneDownload a remote repository and its full history to your machine.
git statusShow changed, staged and untracked files in the working tree.
git addStage changes (files) to be included in the next commit.
git commitRecord staged changes as a new commit with a message.
git logDisplay the commit history of the repository.
git diffShow unstaged or staged differences between states.
git branchList, create or delete branches in the repository.
git checkout / switchSwitch branches or restore files (switch is the modern command).
git mergeJoin another branch's history into the current branch.
git rebaseReapply commits on top of another base commit, rewriting history.
git pullFetch from a remote and merge the changes into the current branch.
git pushUpload local commits to a remote repository.
git stashTemporarily shelve uncommitted changes to reapply later.
git remoteManage the set of remote repositories you track.

Notes

Questions fréquentes

Quelle est la différence entre merge et rebase ?
Merge combine les historiques avec un nouveau commit qui a deux parents. Rebase rejoue vos commits au-dessus d'une autre branche, produisant un historique linéaire mais réécrit les ID de commit.
Comment annuler un commit ?
Utilisez 'git revert <commit>' pour ajouter un nouveau commit qui annule le changement (sûr, historique partagé). 'git reset' réécrit l'historique et ne doit pas être utilisé sur des branches partagées.
Quelle est la différence entre git pull et git fetch ?
Fetch télécharge les commits et références depuis un distant sans toucher votre arbre de travail. Pull fait un fetch puis fusionne ou rebaze ces changements dans votre branche courante.
Quand utiliser git stash ?
Stash met de côté temporairement les changements non commités pour que vous puissiez changer de branche ou tirer proprement, puis les restaure avec 'git stash pop'.