Git Cheat Sheet
Quick reference for Git commands — branching, merging, rebasing, and workflows
git initInitialize a new Git repository in the current directory
git clone <url>Clone a remote repository
git clone --depth 1 <url>Shallow clone (only latest commit) for faster download
git config --global user.name "Name"Set your name for all repositories
git config --global user.email "[email protected]"Set your email for all repositories
git config --global core.editor vimSet default editor for commit messages
git config --global init.defaultBranch mainSet default branch name for new repos
git config --listList all configuration settings
git config --global alias.co checkoutCreate a Git alias (co → checkout)
git config --global credential.helper cacheCache credentials temporarily in memory
git statusShow working tree status (modified, staged, untracked)
git add <file>Stage a specific file for commit
git add .Stage all changes in the current directory
git add -pInteractively stage parts of files (hunk by hunk)
git commit -m "message"Commit staged changes with a message
git commit -am "message"Stage all tracked files and commit in one step
git commit --amendModify the most recent commit (message or files)
git diffShow unstaged changes
git diff --stagedShow staged changes (ready to commit)
git diff HEAD~3Compare working tree with 3 commits ago
git pushPush commits to the remote branch
git pullFetch and merge remote changes into current branch
git pull --rebaseFetch and rebase local commits on top of remote
git fetchDownload remote changes without merging
git branchList all local branches
git branch -aList all branches (local and remote)
git branch <name>Create a new branch
git branch -d <name>Delete a merged branch
git branch -D <name>Force delete an unmerged branch
git branch -m <old> <new>Rename a branch
git switch <branch>Switch to an existing branch
git switch -c <branch>Create and switch to a new branch
git checkout <branch>Switch to a branch (classic syntax)
git checkout -b <branch>Create and switch to a new branch (classic)
git merge <branch>Merge a branch into the current branch
git merge --no-ff <branch>Merge with a merge commit (no fast-forward)
git rebase <branch>Rebase current branch onto another
git rebase --abortAbort an in-progress rebase
git rebase --continueContinue rebase after resolving conflicts
git cherry-pick <commit>Apply a specific commit to the current branch
git remote -vList remote repositories with URLs
git remote add origin <url>Add a new remote repository
git remote rename origin upstreamRename a remote
git remote remove <name>Remove a remote
git remote set-url origin <url>Change the URL of a remote
git push -u origin <branch>Push branch and set upstream tracking
git push origin --delete <branch>Delete a remote branch
git fetch --allFetch from all configured remotes
git fetch --pruneFetch and remove stale remote-tracking branches
git pull origin mainPull changes from a specific remote branch
git push --force-with-leaseForce push safely (fails if remote was updated)
git logShow commit history
git log --onelineShow compact one-line commit history
git log --oneline --graph --allShow branch graph of all branches
git log -p -2Show diffs of the last 2 commits
git log --author="Name"Filter commits by author
git log --since="2 weeks ago"Show commits from the last 2 weeks
git log --statShow commit history with file change statistics
git show <commit>Show details and diff of a specific commit
git blame <file>Show who last modified each line of a file
git shortlog -snShow commit count per author, sorted
git reflogShow history of HEAD movements (recovery tool)
git diff <branch1>..<branch2>Compare two branches
git log --all --grep="fix"Search commit messages for a keyword
git restore <file>Discard unstaged changes to a file
git restore --staged <file>Unstage a file (keep changes in working tree)
git reset HEAD~1Undo last commit, keep changes staged
git reset --soft HEAD~1Undo last commit, keep changes staged
git reset --hard HEAD~1Undo last commit and discard all changes
git reset --hard origin/mainReset branch to match remote (destroys local changes)
git revert <commit>Create a new commit that undoes a specific commit
git clean -fdRemove untracked files and directories
git clean -fdnDry run — show what would be removed
git rm --cached <file>Remove file from staging (keep on disk)
git checkout <commit> -- <file>Restore a file from a specific commit
git stashSave uncommitted changes and clean working tree
git stash push -m "description"Stash with a descriptive message
git stash listList all stashed changesets
git stash popApply the latest stash and remove it from list
git stash applyApply the latest stash but keep it in list
git stash apply stash@{2}Apply a specific stash by index
git stash drop stash@{0}Remove a specific stash
git stash clearRemove all stashed entries
git stash show -pShow the diff of the latest stash
git stash branch <branch>Create a branch from a stash
git tagList all tags
git tag v1.0.0Create a lightweight tag
git tag -a v1.0.0 -m "Release 1.0"Create an annotated tag with message
git tag -a v1.0.0 <commit>Tag a specific commit
git tag -d v1.0.0Delete a local tag
git push origin v1.0.0Push a specific tag to remote
git push origin --tagsPush all local tags to remote
git push origin --delete v1.0.0Delete a remote tag
git show v1.0.0Show information about a tag
git describe --tagsDescribe current commit relative to nearest tag
git submodule add <url> path/Add a submodule to the repository
git submodule initInitialize submodule configuration
git submodule updateFetch and checkout submodule commits
git submodule update --init --recursiveInitialize and update all submodules recursively
git submodule foreach git pullPull latest changes in all submodules
git submodule statusShow the status of all submodules
git submodule deinit path/Unregister a submodule
git rm path/Remove a submodule from the repository
git bisect startStart binary search for a bug-introducing commit
git bisect good <commit>Mark a commit as not containing the bug
git bisect bad <commit>Mark a commit as containing the bug
git bisect resetEnd bisect session and return to original HEAD
git worktree add ../feature feature-branchCreate a linked working tree for a branch
git worktree listList all linked working trees
git archive --format=zip HEAD > repo.zipExport repository as a zip archive
git grep "pattern"Search for a pattern across tracked files
git format-patch -3Create patch files for the last 3 commits
git apply patch.patchApply a patch file
git rev-parse HEADShow the full SHA of the current commit
git gcRun garbage collection to optimize the repository
Commands shown are for Git 2.x and above.
Related Tools
JSON Formatter
Format, validate, and minify JSON data with syntax highlighting
JSON / YAML / TOML Converter
Convert between JSON, YAML, and TOML — validate, format, minify, and download in your browser
Color Scheme Generator
Generate harmonious color palettes — complementary, triadic, analogous, and more
Linux Commands Cheat Sheet
Quick reference for essential Linux commands — files, permissions, networking, and more
Git Cheat Sheet
A free, searchable Git cheat sheet with the most useful commands, flags, and shortcuts in one place. Quickly look up syntax, copy commands, and learn version control with Git faster — perfect for beginners and a handy reference for experienced users.
FAQ
- Is this Git cheat sheet free?
- Yes. The entire cheat sheet is free to browse and copy from, with no sign-up required.
- Can I search for a specific command?
- Yes. Use the search to filter the Git commands instantly and jump straight to the syntax you need.
- Who is the Git cheat sheet for?
- It suits everyone from newcomers learning version control with Git to power users who want a quick reminder of less-used flags and shortcuts.