Git Cheat Sheet
Common Git commands and their usage.
Configuration
git config --global user.name "name"Set global username
git config --global user.email "email"Set global email
git config --global color.ui autoEnable colored output
git config --listList all configurations
Getting Started
git initInitialize a new repository
git clone <url>Clone a repository
git statusCheck status of files
git add .Stage all changes
git commit -m "message"Commit changes
Branching
git branchList all local branches
git branch -aList all branches (local + remote)
git branch <name>Create a new branch
git checkout <name>Switch to a branch
git checkout -b <name>Create and switch to a branch
git branch -d <name>Delete a branch
Remote
git remote -vList remotes
git remote add origin <url>Add remote origin
git push origin <branch>Push branch to remote
git pullPull changes from remote
git fetchFetch changes without merging
Undo
git reset --soft HEAD~1Undo last commit (keep changes)
git reset --hard HEAD~1Undo last commit (discard changes)
git restore <file>Discard changes in a file
git clean -fdRemove untracked files
git checkout .Discard all local changes
Log & Diff
git logShow commit history
git log --onelineCompact commit history
git diffShow unstaged changes
git diff --stagedShow staged changes
git blame <file>Show who changed what and when
Stashing
git stashStash changes
git stash listList stashes
git stash popApply and remove stash
git stash applyApply stash (keep it)