Git Cheatsheet - Quick Git Command Reference
Quick reference for common Git commands. Search, copy, and use Git commands instantly.
git config --global user.name "Name"Set global username
git config --global user.email "email"Set global email
git config --listList all configurations
git config --global core.editor "vim"Set default text editor
git config --global init.defaultBranch mainSet default branch name
git config --global alias.co checkoutSet command alias
git config --global credential.helper cacheCache credentials
git initInitialize a new repository
git init --bareInitialize bare repository
git clone <url>Clone a remote repository
git clone -b <branch> <url>Clone specific branch
git clone --depth 1 <url>Shallow clone (latest commit only)
git clone --recursive <url>Clone with submodules
git statusCheck working directory status
git status -sShort status format
git add <file>Add file to staging area
git add .Add all changes
git add -AAdd all changes including deletions
git add -pInteractive add (patch mode)
git rm <file>Delete file and stage
git rm --cached <file>Remove file from staging
git mv <old> <new>Rename file
git commit -m "message"Commit staged changes
git commit -am "message"Add and commit all changes
git commit --amendAmend last commit
git commit --amend --no-editAmend without changing message
git branchList local branches
git branch -aList all branches
git branch -rList remote branches
git branch --mergedList merged branches
git branch <name>Create new branch
git branch -d <name>Delete branch
git branch -D <name>Force delete branch
git branch -m <old> <new>Rename branch
git checkout <branch>Switch branch
git checkout -b <name>Create and switch branch
git checkout --track origin/<branch>Track remote branch
git switch <branch>Switch branch (new)
git switch -c <name>Create and switch (new)
git merge <branch>Merge branch into current
git merge --no-ff <branch>Merge with no fast-forward
git merge --squash <branch>Squash merge (no commit)
git merge --abortAbort merge
git rebase <branch>Rebase onto branch
git rebase -i HEAD~3Interactive rebase last 3 commits
git rebase --continueContinue rebase
git rebase --abortAbort rebase
git cherry-pick <commit>Cherry-pick a commit
git remote -vView remote repositories
git remote add origin <url>Add remote repository
git remote remove <name>Remove remote repository
git remote set-url origin <url>Change remote URL
git fetchFetch from remote
git fetch --pruneFetch and prune remote branches
git pullPull and merge from remote
git pull --rebasePull with rebase
git pushPush to remote
git push -u origin <branch>Push and set upstream
git push --forceForce push
git push --force-with-leaseForce push with lease
git push origin --delete <branch>Delete remote branch
git logView commit history
git log --onelineCompact history view
git log --oneline --graphCompact graphical history
git log --graph --all --decorateFull graphical history
git log --statShow change statistics
git log -3Show last 3 commits
git log --author="name"Filter by author
git log --since="1 week ago"Filter by time
git log --grep="keyword"Filter by commit message
git diffView working directory changes
git diff --cachedView staged changes
git diff HEADView all changes
git show <commit>Show commit details
git blame <file>Show line-by-line author
git shortlog -snAuthor commit count
git tagList all tags
git tag <name>Create lightweight tag
git tag -a <name> -m "msg"Create annotated tag
git tag -d <name>Delete local tag
git push origin <tag>Push tag to remote
git push origin --tagsPush all tags
git push origin --delete <tag>Delete remote tag
git stashStash current changes
git stash push -m "message"Stash with message
git stash push -uStash including untracked
git stash listList stashes
git stash showShow latest stash changes
git stash popPop latest stash
git stash applyApply stash without removing
git stash dropDrop latest stash
git stash clearClear all stashes
git stash branch <name>Create branch from stash
git reset HEAD <file>Unstage file
git reset --soft HEAD~1Soft reset to last commit
git reset --mixed HEAD~1Mixed reset (default)
git reset --hard HEAD~1Hard reset to last commit
git revert <commit>Revert a commit
git checkout -- <file>Discard file changes
git restore <file>Restore file (new)
git restore --staged <file>Unstage file (new)
git clean -nPreview removing untracked
git clean -fdRemove untracked files and dirs
git submodule add <url>Add submodule
git submodule update --initInit and update submodules
git submodule update --recursiveUpdate submodules recursively
git submodule deinit <path>Remove submodule
git reflogView reference log
git reflog show HEAD@{10}Show specific reference
git gcGarbage collection
git fsckCheck repository integrity
git archive -o latest.zip HEADExport repository as archive
git bundle create repo.bundle --allCreate repository bundle
git bundle unbundle repo.bundleUnbundle repository
git notes add -m "note" <commit>Add commit note
git filter-branch --force --index-filterRewrite history (use with caution)
git config --global core.ignorecase falseCase sensitive filenames
git config --global core.filemode falseIgnore file mode changes
git config --global push.default simpleSet default push mode
git config --global pull.rebase trueDefault to rebase on pull
git config --global rerere.enabled trueEnable reuse recorded resolution
git check-ignore -v <file>Check which rule ignores file
git ls-filesList tracked files
git ls-files --others --exclude-standardList untracked files
git commit --fixup=<commit>Create fixup commit
git commit --squash=<commit>Create squash commit
git branch --set-upstream-to=origin/<branch>Set upstream tracking
git branch --unset-upstreamUnset upstream tracking
git branch --edit-descriptionEdit branch description
git merge --no-commit --no-ff <branch>Merge without committing
git merge-base <branch1> <branch2>Find common ancestor
git push origin :<branch>Delete remote branch (old syntax)
git push --set-upstream origin <branch>Push and set upstream
git push --follow-tagsPush with following tags
git log --pretty=format:"%h %s" --graphCustom format log
git log --decorate --oneline --graph --allAll branches graph log
git whatchangedShow what changed per commit
git diff-tree --no-commit-id --name-only -r <commit>Show commit changed files
git stash save "message"Save stash (old syntax)
git stash createCreate stash without storing
git stash store <stash-hash>Store specific hash as stash
git revert HEADRevert last commit
git revert HEAD~1..HEADRevert recent commit range
git update-index --assume-unchanged <file>Assume file unchanged
git update-index --no-assume-unchanged <file>Cancel assume unchanged
git update-index --skip-worktree <file>Skip worktree check
git worktree add <path> <branch>Add worktree
git worktree listList worktrees
git worktree remove <path>Remove worktree
git config --global core.autocrlf trueAuto handle line endings
git config --global color.ui autoEnable colored output
git config --global merge.tool vimdiffSet merge tool
git config --global diff.tool vimdiffSet diff tool
git clone --mirror <url>Clone mirror repository
git clone --single-branch <url>Clone single branch only
git clone --branch <tag> <url>Clone specific tag
git add --dry-run <file>Dry run add operation
git add -f <file>Force add ignored file
git rm --cached <file>Remove from staging
git mv <old> <new>Rename file
git commit --amend --no-editAmend without changing message
git commit --allow-emptyAllow empty commit
git commit --verboseShow diff in commit message
git branch -vvShow branch verbose info
git branch --contains <commit>Find branches containing commit
git branch --no-mergedShow unmerged branches
git merge --abortAbort merge
git merge --continueContinue merge
git remote get-url originGet remote URL
git remote set-branches origin <branch>Set tracking branches
git remote show originShow remote details
git log --since="2 weeks ago"Commits since 2 weeks ago
git log --until="2024-01-01"Commits until date
git log --author="name"Filter by author
git log -S "string"Search code changes
git log -p <file>File history with diff
git tag -a <tag> -m "message"Create annotated tag
git tag -d <tag>Delete tag
git push origin --delete <tag>Delete remote tag
git stash branch <branch>Create branch from stash
git stash clearClear all stashes
git reset --soft HEAD~1Soft reset last commit
git reset --mixed HEAD~1Mixed reset (default)
git checkout -- <file>Discard file changes
git submodule foreach <command>Run command on all submodules
git submodule syncSync submodule URLs
git shortlog -snCommit summary by author
git describe --tagsDescribe nearest tag
git cherry-pick --abortAbort cherry-pick
git cherry-pick --continueContinue cherry-pick
git bisect startStart bisect
git bisect badMark current as bad
git bisect good <commit>Mark commit as good
git bisect resetEnd bisect
194 of 194 commands shown
Related Tools
More Code & Dev Tools
Color Palette Generator
Generate harmonious color palettes online. Create color sche...
CSS Formatter
Format and minify CSS online. Beautify CSS code or compress ...
CSS Gradient Generator
Generate CSS gradients online. Linear and radial gradients w...
Color Extractor
Extract colors from images online. Get dominant colors and c...
Code Minifier
Minify HTML, CSS, and JavaScript code. Reduce file size by r...
JavaScript Obfuscator
Obfuscate and protect JavaScript code. Make your code harder...
XML Formatter
Format and minify XML online. Beautify XML code or compress ...
Color Contrast Checker
Check color contrast ratios for WCAG compliance. Ensure acce...
HTML Formatter
Format and minify HTML online. Beautify HTML code or compres...
Timestamp Converter
Convert between Unix timestamp and human-readable date. Supp...
Regex Cheatsheet
Quick reference for regular expression patterns. Character c...
Code Share
Create and share code snippets online. Syntax highlighting a...