๐Ÿ“‹ Git Cheatsheet

Quick reference for everyday Git commands ยท gitlearn.mohitm.github.io

๐Ÿ”ง Setup

git config user.name "Name"Set your name
git config user.email "e@mail"Set your email
git initInit a new repo
git clone <url>Clone a remote repo

๐Ÿ“ธ Staging & Committing

git statusShow working tree status
git add <file>Stage a file
git add .Stage all changes
git commit -m "msg"Commit with message
git commit --amendEdit last commit

๐ŸŒฟ Branching

git branchList branches
git branch <name>Create branch
git checkout <name>Switch branch
git checkout -b <name>Create & switch
git branch -d <name>Delete branch

๐Ÿ”€ Merging & Rebasing

git merge <branch>Merge into current
git rebase <branch>Rebase onto branch
git rebase -i HEAD~nInteractive rebase
git cherry-pick <id>Apply a commit

๐ŸŒ Remote

git remote add origin <url>Add remote
git push origin <branch>Push branch
git pullFetch & merge
git fetchFetch only
git push -u origin mainPush & track

๐Ÿ” Inspect & Undo

git log --onelineCompact history
git diffShow unstaged diff
git stashStash changes
git stash popRestore stash
git reset --hard HEADDiscard all changes