Git Cheat Sheet
Setup
git initgit clone <url>git config --global user.name "<name>"git config --global user.email "<email>"Basic Commands
git statusgit add <file>git add .git commit -m "<message>"git push origin <branch>git pull origin <branch>Branching
git branchgit branch <name>git checkout <branch>git checkout -b <name>git merge <branch>git branch -d <name>History
git loggit log --onelinegit diffgit diff --stagedgit show <commit>Undo Changes
git reset <file>git reset --hardgit revert <commit>git stashgit stash popRemote
git remote -vgit remote add origin <url>git fetch originAbout the Git Memo
Git has hundreds of commands and options, but daily work uses about 30 of them. This cheat sheet covers the essential Git commands every developer needs: branching, merging, staging, stashing, and fixing mistakes.
Each command includes a brief explanation and the most useful flags. Use it as a quick reference when you forget the exact syntax for rebasing, cherry-picking, or undoing a commit.
How to use
- Browse by category: setup, staging, branching, remotes, or history.
- Find the command you need.
- Copy it with one click.
- Check the flags section for advanced options.
Frequently Asked Questions
Is this a complete Git reference? ▾
It covers the 30 most-used commands for daily work: branching, merging, staging, undoing commits, and working with remotes. For advanced topics, consult the official Git documentation.
How do I undo my last commit? ▾
Use git reset --soft HEAD~1 to undo the commit but keep changes staged. Use git reset --hard HEAD~1 to undo and discard changes. Use git revert HEAD to create a new commit that undoes the previous one.