⚙️
Setup & Config
git initInitialize new repo
git clone <url>Clone remote repo
git config --global user.nameSet global username
git config --global user.emailSet global email
git config --listView all config
git config --global alias.st statusCreate alias
📝
Stage & Commit
git statusShow working tree status
git add <file>Stage file
git add .Stage all changes
git add -pInteractively stage hunks
git commit -m "msg"Commit with message
git commit -am "msg"Stage tracked + commit
git commit --amendEdit last commit
🔍
History & Diff
git logShow commit history
git log --oneline --graphCompact branch graph
git log -p <file>History of file
git diffUnstaged changes
git diff --stagedStaged vs last commit
git diff main..featureCompare branches
git show <hash>Show commit details
🌿
Branches
git branchList branches
git branch <name>Create branch
git branch -d <name>Delete branch (safe)
git branch -D <name>Force delete branch
git branch -aList all + remote
git checkout -b <name>Create + switch
git switch -c <name>Create + switch (modern)
git switch <name>Switch to branch
🔀
Merge & Rebase
git merge <branch>Merge into current
git merge --no-ffForce merge commit
git merge --squashSquash to one commit
git merge --abortCancel conflicted merge
git rebase <branch>Rebase onto branch
git rebase -i HEAD~3Interactive rebase
git rebase --abortCancel rebase
🌐
Remote
git remote -vList remotes
git remote add origin <url>Add remote
git fetch --allFetch all remotes
git pullFetch + merge
git pull --rebaseFetch + rebase
git push origin <branch>Push branch
git push -u origin <branch>Push + set upstream
git push --force-with-leaseSafe force push
↩️
Undo Changes
git restore <file>Discard working changes
git restore --staged <file>Unstage file
git reset --soft HEAD~1Undo commit, keep staged
git reset --mixed HEAD~1Undo + unstage
git reset --hard HEAD~1Undo + discard all
git revert <hash>Safe undo (new commit)
git clean -fdRemove untracked files
📦
Stash
git stashStash changes
git stash -m "desc"Stash with message
git stash listList stashes
git stash popApply + drop latest
git stash apply stash@{n}Apply specific stash
git stash dropDelete latest stash
🚀
Advanced
git cherry-pick <hash>Apply specific commit
git bisect startStart binary search
git reflogView HEAD history
git tag v1.0.0Create tag
git tag -a v1.0.0 -m "Release"Annotated tag
git push origin --tagsPush all tags
git blame <file>Who changed each line
git submodule add <url>Add submodule
git shortlog -snCommits per author
🙈
.gitignore Patterns
*.logIgnore all .log files
node_modules/Ignore directory
!important.logUn-ignore specific file
**/*.tmpIgnore in all subdirs
git rm --cached <file>Untrack committed file