Snabbreferens för Git-kommandon

Git spårar ändringar i dina filer som en serie commits i ett repository. Dessa kommandon täcker det dagliga flödet: starta ett repo, spara arbete, grenar, sammanfogning och delning med en fjärr. Håll detta blad öppet medan du lär dig.

Uppdaterad:

KommandoVad den gör
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.

Anteckningar

Vanliga frågor

Vad är skillnaden mellan merge och rebase?
Merge kombinerar historiker med en ny commit som har två föräldrar. Rebase spelar upp dina commits ovanpå en annan gren, vilket ger en linjär historik men skriver om commit-ID:n.
Hur ångrar jag en commit?
Använd 'git revert <commit>' för att lägga till en ny commit som ångrar ändringen (säkert, delad historik). 'git reset' skriver om historiken och bör inte användas på delade grenar.
Vad är skillnaden mellan git pull och git fetch?
Fetch laddar ner commits och referenser från en fjärr utan att röra ditt arbetslager. Pull gör en fetch och mergear eller rebasar sedan ändringarna in i din nuvarande gren.
När ska jag använda git stash?
Stash lägger tillfälligt undan ej commitade ändringar så att du kan byta gren eller hämta rent, och återställer dem senare med 'git stash pop'.