Git Cheatsheet
Comprehensive Git command reference with 150+ commands organized by category. Search, filter by category, and click to copy any command.
Git Cheatsheet
Essential Git commands for everyday use
Commands
Categories
Favorites
Sections
git config --global user.name '[name]'Set global username
git config --global user.email '[email]'Set global email
git config --global core.editor 'code --wait'Set VS Code as default editor
git config --global init.defaultBranch mainSet default branch name
git config --listList all config settings
git config --global alias.co checkoutCreate alias 'co' for checkout
git initInitialize new repository
git clone [url]Clone remote repository
git clone --depth 1 [url]Shallow clone (latest only)
git clone --branch [branch] [url]Clone specific branch
git statusShow working tree status
git add [file]Stage specific file
git add .Stage all changes
git add -pStage changes interactively
git commit -m '[message]'Commit with message
git commit -am '[message]'Stage and commit tracked files
git commit --amendAmend last commit
git commit --amend -m '[new message]'Change last commit message
git rm [file]Remove file from repo and disk
git rm --cached [file]Remove from repo, keep on disk
git mv [old] [new]Rename/move file
git restore [file]Restore file (modern)
git restore --staged [file]Unstage file (modern)
git branchList local branches
git branch -aList all branches
git branch [name]Create new branch
git branch -d [name]Delete branch (safe)
git branch -D [name]Delete branch (force)
git branch -m [old] [new]Rename branch
git checkout [branch]Switch to branch
git checkout -b [name]Create and switch to branch
git switch [branch]Switch branch (modern)
git switch -c [name]Create and switch (modern)
git checkout -Switch to previous branch
git merge [branch]Merge branch into current
git merge --no-ff [branch]Merge with merge commit
git merge --squash [branch]Squash merge (no commit)
git merge --abortAbort merge in progress
git rebase [branch]Rebase onto branch
git rebase -i HEAD~[n]Interactive rebase last n commits
git rebase --continueContinue after resolving conflicts
git rebase --abortAbort rebase
💡 Never rebase commits pushed to shared repository
git cherry-pick [commit]Apply commit to current branch
git cherry-pick --no-commit [commit]Apply without committing
git remote -vList remotes with URLs
git remote add [name] [url]Add remote
git remote remove [name]Remove remote
git remote set-url [name] [url]Change remote URL
git fetchFetch all remotes
git fetch --pruneFetch and remove deleted remote branches
git pullFetch and merge
git pull --rebaseFetch and rebase
git pushPush to tracked remote
git push -u origin [branch]Push and set upstream
git push --force-with-leaseSafe force push
git push origin --delete [branch]Delete remote branch
git push --tagsPush all tags
git reset [file]Unstage file
git reset --soft HEAD~1Undo commit, keep staged
git reset --mixed HEAD~1Undo commit, keep changes
git reset --hard HEAD~1Undo commit, discard changes
git reset --hard origin/[branch]Reset to remote branch
💡 --soft keeps staged, --mixed unstages, --hard discards
git revert [commit]Create commit that undoes changes
git clean -nPreview untracked files to remove
git clean -fdRemove untracked files and directories
git reflogShow reference log
git checkout [reflog-hash]Recover from reflog
💡 Reflog keeps history for ~90 days
git logShow commit history
git log --onelineCompact log
git log --graph --oneline --allFull graph view
git log --author='[name]'Filter by author
git log -S '[text]'Search commits by content
git diffShow unstaged changes
git diff --stagedShow staged changes
git diff [branch1]..[branch2]Compare branches
git diff --name-onlyShow changed file names
git show [commit]Show commit details
git blame [file]Show who changed each line
git shortlog -snCommit count by author
git stashStash changes
git stash push -m '[message]'Stash with message
git stash -uStash including untracked
git stash listList all stashes
git stash show -pShow stash diff
git stash popApply and remove latest stash
git stash applyApply latest stash
git stash dropRemove latest stash
git stash clearRemove all stashes
git tagList all tags
git tag [name]Create lightweight tag
git tag -a [name] -m '[message]'Create annotated tag
git tag -d [name]Delete local tag
git push origin [tag]Push tag to remote
git push origin --delete [tag]Delete remote tag
git submodule add [url]Add submodule
git submodule update --init --recursiveInit and update all
git clone --recurse-submodules [url]Clone with submodules
git worktree add [path] [branch]Create worktree
git worktree listList worktrees
git worktree remove [path]Remove worktree
git bisect startStart bisect session
git bisect badMark current as bad
git bisect good [commit]Mark commit as good
git bisect resetEnd bisect session
💡 Binary search to find bug-introducing commit
Git Workflow Quick Reference
git init / clone
git add .
git commit -m ""
git push
git pull
What is Git?
Git is a distributed version control system that tracks changes in source code during software development. It allows multiple developers to work together on non-linear development through branches, and provides tools for merging changes, tracking history, and collaborating on projects.
Common Git Workflows
- Feature Branch Workflow - Create branches for new features, merge when complete
- Gitflow - Structured branching model with develop, feature, release, and hotfix branches
- Trunk-Based Development - Short-lived branches merged frequently to main
- Forking Workflow - Fork repositories, make changes, submit pull requests
Best Practices
- Write clear, descriptive commit messages
- Commit early and often with small, focused changes
- Use branches for features, fixes, and experiments
- Pull before pushing to avoid conflicts
- Never force push to shared branches
- Use .gitignore to exclude unnecessary files