Bookmark this page! Here is your complete, print-friendly Git CLI Master Cheat Sheet grouping every command, syntax pattern, and essential flag required for daily development, university exams, and emergency production troubleshooting.
git config --global user.name "Your Name" # Set global author name
git config --global user.email "you@email.com" # Set global email
git config --global init.defaultBranch main # Default new branch to 'main'
git config --global core.editor "code --wait" # Use VS Code as editor
git config --global core.autocrlf true # Windows CRLF line conversion
git config --global pull.rebase true # Auto-rebase on pull
git config --list --show-origin # Inspect active config & origins
git init # Initialize new repo in current dir
git init <project-name> # Create folder and init repo
git clone <url> # Clone complete repo with history
git clone --depth 1 <url> # Shallow clone latest commit only
git clone --recurse-submodules <url> # Clone repo and all submodules
git status # Check working tree & staging state
git status -s # Compact short status output
git add <file> # Stage specific file
git add . # Stage all changes in current folder
git add -A # Stage all changes across entire repo
git add -p <file> # Stage individual hunks interactively
git commit -m "feat: message" # Commit with inline message
git commit -am "fix: message" # Stage tracked files and commit
git commit --amend --no-edit # Absorb staged edits into last commit
git log --oneline # Compact single-line commit history
git log --graph --oneline --decorate --all # ASCII branching tree view
git log -n 5 # Show last 5 commits only
git log --author="Name" # Filter commits by author
git log -S "query" # Pickaxe search: find string changes
git log -L 20,40:app.js # Trace line range evolution
git diff # Unstaged diff (working vs index)
git diff --staged # Staged diff (index vs HEAD)
git diff branch1..branch2 # Compare tips of two branches
git blame -L 10,25 app.js # Line-by-line author attribution
git branch # List local branches
git branch -a # List local + remote-tracking branches
git branch -vv # List branches with upstream tracking info
git branch <branch-name> # Create branch without switching
git switch <branch-name> # Switch to existing branch
git switch -c <new-branch> # Create branch and switch to it
git switch - # Switch to previously checked out branch
git branch -m <new-name> # Rename current branch
git branch -d <branch-name> # Safe delete merged branch
git branch -D <branch-name> # Force delete unmerged branch
git merge <branch> # Merge branch into current branch
git merge --no-ff <branch> # Force merge commit (no fast-forward)
git merge --abort # Abort active merge and restore clean state
git rebase <upstream-branch> # Replay current branch commits onto base
git rebase -i HEAD~3 # Interactive rebase (squash, reword, drop)
git rebase --continue # Continue rebase after resolving conflict
git rebase --abort # Abort active rebase
git stash # Save dirty working changes to stack
git stash -u -m "note" # Stash including untracked files
git stash list # View all saved stashes
git stash pop # Apply top stash and delete it
git stash apply stash@{1} # Apply specific stash and keep on stack
git stash drop stash@{0} # Delete specific stash
git remote -v # Inspect remote URLs
git remote add origin <url> # Add remote origin
git remote set-url origin <url> # Change remote URL
git push -u origin main # Push and configure upstream tracking
git push # Shorthand push to upstream
git push --force-with-lease # Safe force push check
git fetch origin # Download remote changes without merging
git pull # Fetch and merge into active branch
git pull --rebase # Fetch and rebase into active branch
git tag -a v1.0.0 -m "Release v1.0.0" # Create annotated release tag
git push origin v1.0.0 # Push tag to GitHub
git push origin --tags # Push all tags to GitHub
git restore <file> # Discard unstaged edits in file
git restore --staged <file> # Unstage file, keeping edits on disk
git clean -df # Delete untracked files & directories
git reset --soft HEAD~1 # Undo commit; keep files staged
git reset --mixed HEAD~1 # Undo commit; unstage files (default)
git reset --hard HEAD~1 # Undo commit; wipe out all edits (danger!)
git revert <commit-hash> # Create safe inverse commit
git reflog # View HEAD transition history time machine
git reset --hard HEAD@{2} # Restore repo to state 2 steps ago
Strengthen your version control mastery by studying these connected classes:
Execute commands from the cheat sheet in realistic multi-branch scenarios.
Learn the 'why' behind each CLI command to ace your technical job interviews.
Quickly look up solutions for detached HEAD, merge conflicts, and push rejections.
Explore the step-by-step curriculum from beginner setup to advanced internals.
Advance your software engineering skills with the next topic in our synchronized curriculum.
Continue to Troubleshooting & Master FAQ → Previous: ← 120+ Interview & Viva Q&A | Full Syllabus