HomeCheat SheetsGit Commands & Workflow Cheat Sheet
100% Client-Side β€’ 0 B Data Leaves Browser
git

Git Commands & Workflow Cheat Sheet

The definitive Git command reference for developers. Covers cloning, branching, staging, rebasing, stashing, and conflict resolution.

Repository Setup & Staging

Initialize a brand new local Git repository in current directorygit init
Clone a remote repository with full historygit clone <url>
Show the working tree status, staged and unstaged filesgit status
Stage all modified, new, and deleted files for next commitgit add .
Commit staged changes with a descriptive messagegit commit -m "feat: message"

Branching & Merging

List all local branchesgit branch
Create a new branch and immediately switch to itgit checkout -b <branch-name>
Modern command to switch branches cleanlygit switch <branch-name>
Merge specified branch into current active branchgit merge <branch-name>
Safely delete a merged local branchgit branch -d <branch-name>

Undoing Changes & Stashing

Temporarily shelve uncommitted dirty working changesgit stash
Restore previously stashed changes and remove from stash listgit stash pop
Undo last commit but keep changes staged in working directorygit reset --soft HEAD~1
Permanently discard last commit and uncommitted changes (destructive)git reset --hard HEAD~1
Safely undo changes by creating a new inverse commitgit revert <commit-hash>

Frequently Asked Questions

β€’ What is the difference between git merge and git rebase?

Git merge preserves the complete chronological history including branch nodes, while git rebase re-applies your commits on top of another branch, resulting in a cleaner linear project history.

β€’ How do I undo a commit pushed to remote?

Use git revert <commit_hash> to create a new commit that reverses the unwanted changes without rewriting shared Git history.