Git Cheatsheet
Essential Git commands organized by category. Keep this reference handy for your daily development workflow.
5 min read•Last updated: 2024
Dai Aoki
CEO at init, Inc. / CTO at US & JP startups / Creator of WebTerm
Quick Reference
Setup
git initInitialize repogit clone [url]Clone repogit config --global user.nameSet namegit config --global user.emailSet emailBasic
git statusCheck statusgit add [file]Stage filegit add .Stage allgit commit -m "msg"Commit changesBranch
git branchList branchesgit branch [name]Create branchgit checkout [branch]Switch branchgit checkout -b [name]Create & switchgit merge [branch]Merge branchgit branch -d [name]Delete branchHistory
git logView historygit log --onelineCompact historygit diffUnstaged changesgit diff --stagedStaged changesgit show [commit]Commit detailsUndo
git checkout -- [file]Discard changesgit reset [file]Unstage filegit reset --soft HEAD~1Undo commit (keep)git reset --hard HEAD~1Undo commit (discard)git revert [commit]Revert commitRemote
git remote -vList remotesgit remote add [name] [url]Add remotegit pushPush to remotegit pullPull from remotegit fetchFetch changesDownloadable Image Preview
Failed to generate preview
Setup & Config
git config --global user.name "[name]"Set your namegit config --global user.email "[email]"Set your emailgit initInitialize a new repogit clone [url]Clone a repositoryBasic Commands
git statusCheck repo statusgit add [file]Stage a filegit add .Stage all changesgit commit -m "[message]"Commit staged changesgit pushPush to remotegit pullPull from remoteBranching
git branchList branchesgit branch [name]Create new branchgit checkout [branch]Switch to branchgit checkout -b [name]Create and switchgit merge [branch]Merge branchgit branch -d [name]Delete branchHistory & Diff
git logView commit historygit log --onelineCompact historygit diffShow unstaged changesgit diff --stagedShow staged changesgit show [commit]Show commit detailsUndo & Reset
git checkout -- [file]Discard file changesgit reset [file]Unstage a filegit reset --soft HEAD~1Undo last commit (keep changes)git reset --hard HEAD~1Undo last commit (discard changes)git revert [commit]Revert a commitRemote
git remote -vList remotesgit remote add [name] [url]Add remotegit fetchFetch remote changesgit push -u origin [branch]Push and track branch