Scheda riepilogativa dei comandi Git

Git registra le modifiche dei file come una serie di commit in un repository. Questi comandi coprono il flusso quotidiano: creare un repo, salvare il lavoro, ramificare, unire e condividere con un remoto. Tieni questa scheda aperta mentre impari.

Aggiornato:

ComandoCosa fa
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.

Note

Domande frequenti

Qual è la differenza tra merge e rebase?
Merge unisce gli storici con un nuovo commit che ha due genitori. Rebase ripropone i tuoi commit sopra un altro branch, producendo una storia lineare ma riscrivendo gli ID dei commit.
Come annullo un commit?
Usa 'git revert <commit>' per aggiungere un nuovo commit che annulla la modifica (sicuro, cronologia condivisa). 'git reset' riscrive la cronologia e non va usato su branch condivisi.
Qual è la differenza tra git pull e git fetch?
Fetch scarica commit e riferimenti da un remoto senza toccare il tuo albero di lavoro. Pull fa fetch e poi unisce o fa rebase di quei cambiamenti nel branch corrente.
Quando dovrei usare git stash?
Stash accantona temporaneamente le modifiche non committate così puoi cambiare branch o fare pull in pulito, poi le ripristini con 'git stash pop'.