☰ Git lessons Home › Tutorials › Git › Git Cheat Sheet A cheat sheet is a one-page summary to keep next to you while you work, like the list of phone numbers by a hotel telephone. This one lists every command taught in this course, grouped by the job it does, with the options you will use most and a link to the lesson that explains it. Use your browser's Print command to keep a paper copy.
The Daily Loop in Ten Commands Step Command Get the latest work git switch main and git pullStart a branch git switch -c feature/<name>See what changed git status and git diffStage git add <file> or git add -pCommit git commit -m "<message>"Share the branch git push -u origin feature/<name>Update the branch git pull --rebase origin mainFix the last commit git commit --amendPut work aside git stash and git stash popFind a lost commit git reflog
When something goes wrong, run git status first. It says which branch you are on, what is staged, and whether a merge or rebase is in progress, with the command to continue or abort.
Setup and Help Command It is used to Common options git config (lesson )read and write settings --global, --local, --system, --list, --show-origin, --unset, --editgit help (lesson )open the manual for a command -a (all commands), -g (guides), <command>git version / git --version (lesson )show the installed version
Creating and Getting Repositories Command It is used to Common options git init (lesson )create a new repository -b <branch>, --bare, --object-format=sha256, --ref-format=reftablegit clone (lesson )copy a repository and check out a branch --depth, --branch, --filter=blob:none, --recurse-submodules, --bare, --mirror
Everyday Changes Command It is used to Common options git status (lesson )show the state of the working tree and index -s, -b, --porcelain, --ignoredgit add (lesson )stage changes ., -A, -u, -p, -N, --dry-rungit commit (lesson )record staged changes as a commit -m, -a, -v, --amend, --no-edit, --fixup, -S, --allow-emptygit rm (lesson )remove files from the working tree and index --cached, -r, -fgit mv (lesson )move or rename a tracked file -fgit restore (lesson )restore files in the working tree or index --staged, --worktree, --source=<commit>, -p, --ours, --theirsgit clean (lesson )delete untracked files -n, -f, -d, -x, -igit check-ignore (lesson )explain why a path is ignored -v
History and Comparison Command It is used to Common options git log (lesson )list commits --oneline, --graph, --all, --stat, -p, --author, --since, --grep, -S, -G, -L, --follow, --pretty=format:git show (lesson )show a commit, tag or file at a commit --stat, --name-only, <commit>:<path>git diff (lesson )compare working tree, index and commits --staged, HEAD, a..b, a...b, --stat, --name-only, --word-diff, --color-wordsgit shortlog (lesson )summarize commits by author -s, -n, -egit blame (lesson )show who last changed each line -L, -w, -C, --ignore-revs-filegit grep (lesson )search tracked files (in any commit) -n, -i, -w, -c, <commit>git bisect (lesson )binary-search history for a bad commit start, good, bad, skip, run, reset, loggit describe (lesson )name a commit after the nearest tag --tags, --always, --dirtygit range-diff (lesson )compare two versions of a series of commits git cherry (lesson )find commits not yet applied upstream -v
Branches and Merging Command It is used to Common options git branch (lesson )list, create, rename and delete branches -v, -vv, -a, -m, -d, -D, --merged, --no-merged, -ugit switch (lesson )switch branches -c, -C, --detach, - (previous branch)git checkout (legacy for these jobs) (lesson )switch branches or restore files -b, --, --ours, --theirsgit merge (lesson )join histories --no-ff, --ff-only, --squash, --abort, --continue, -X ours/theirs, -s <strategy>git mergetool (lesson )resolve conflicts in a merge tool --tool=<name>git rebase (lesson )replay commits on a new base -i, --onto, --continue, --skip, --abort, --autosquash, --update-refs, -x, --autostashgit cherry-pick (lesson )apply existing commits on the current branch -x, -n, -m, --continue, --abortgit revert (lesson )create a commit that undoes another -m 1, --no-edit, -ngit reset (lesson )move the branch and optionally the index and working tree --soft, --mixed, --hard, --keep, <path>git rerere (lesson )reuse recorded conflict resolutions status, diff, forgetgit merge-base (lesson )find the best common ancestor --is-ancestor, --fork-pointgit merge-tree (lesson )merge without touching the working tree --write-tree
Remotes and Sharing Command It is used to Common options git remote (lesson )manage remote connections -v, add, rename, remove, set-url, prunegit fetch (lesson )download objects and refs --all, --prune, --tags, --depth, --unshallowgit pull (lesson )fetch and integrate --rebase, --ff-only, --no-rebasegit push (lesson )upload commits and update remote refs -u, --force-with-lease, --force-if-includes, --tags, --delete, --dry-rungit ls-remote (lesson )list refs on a remote --heads, --tags
Saving Work and Releases Command It is used to Common options git stash (lesson )save and restore work in progress push -m, -u, -a, -p, list, show -p, apply, pop, drop, clear, branchgit tag (lesson )create, list and delete tags -a, -m, -s, -d, -l, -ngit archive (lesson )export a tree as zip or tar --format, --prefix, -ogit bundle (lesson )pack a repository into one file create, verify, list-headsgit format-patch (lesson )write commits as email-style patches -n, -o, --cover-lettergit am (lesson )apply email-style patches as commits --continue, --abort, -3git apply (lesson )apply a diff to the working tree --check, --stat, -3git notes (lesson )attach notes to commits add, show, list
Recovery and Maintenance Command It is used to Common options git reflog (lesson )show where HEAD and branches have been show <ref>, expiregit fsck (lesson )check integrity; find unreachable objects --unreachable, --lost-found, --fullgit gc (lesson )pack objects and clean up --aggressive, --prune=nowgit maintenance (lesson )schedule background optimization start, stop, run --task=…git prune (lesson )remove unreachable loose objects -ngit count-objects (lesson )show object counts and disk use -v, -H
Bigger Setups Command It is used to Common options git worktree (lesson )manage several working folders add, list, remove, prune, lockgit submodule (lesson )manage nested repositories add, update --init --recursive, status, foreach, syncgit subtree (lesson )merge another project into a subfolder add, pull, push, split, --squashgit sparse-checkout (lesson )check out only part of a repository set, add, list, disable, --conegit lfs (extension) (lesson )store large files outside the repository install, track, ls-files, migratescalar (lesson )set up very large repositories for speed clone, register, run
Signing and Verification Command It is used to Common options git commit -S / git tag -s (lesson )sign a commit or tag config: gpg.format ssh, user.signingKey, commit.gpgSign git verify-commit / git verify-tag (lesson )check a signature -v
Plumbing Command It is used to git hash-object (lesson )compute an object's hash (and store it with -w) git cat-file (lesson )show an object's type (-t), size (-s) or content (-p) git ls-files (lesson )list files in the index (--stage shows modes and hashes) git ls-tree (lesson )list a tree object git update-index (lesson )change the index directly (--add, --cacheinfo, --chmod=+x) git write-tree (lesson )write the index as a tree object git commit-tree (lesson )create a commit object from a tree git update-ref (lesson )set a ref safely git symbolic-ref (lesson )read or set a symbolic ref such as HEAD git rev-parse (lesson )turn names into hashes (--show-toplevel, --abbrev-ref HEAD) git rev-list (lesson )list commits reachable from refs git show-ref / git for-each-ref (lesson )list refs (with a custom --format) git name-rev (lesson )name a commit relative to refs git verify-pack (lesson )inspect a packfile
Safety Net If you need to Run Cancel a merge, rebase or cherry-pick in progress git merge --abort, git rebase --abort, git cherry-pick --abortKeep a copy before a risky command git branch backupUndo the last commit, keep the changes git reset --soft HEAD~1Undo a pushed commit git revert <commit>Force-push your own branch safely git push --force-with-lease --force-if-includesGet back anything you committed git reflog, then git branch rescue <id>
For explanations and examples, see the lessons linked in each table, and for practice questions, 50 Git Interview Questions and Answers .
✕ Was this tutorial helpful?
👍 Yes 👎 No