Git Cheat Sheet
The Git commands developers reach for every day, grouped by task.
Setup
git initCreate a new repositorygit clone <url>Clone a remote repositorygit config --global user.name "Name"Set your nameStaging & committing
git statusShow working tree statusgit add <file>Stage a file (use . for all)git commit -m "msg"Commit staged changesgit commit -am "msg"Stage tracked files and commitBranches
git branchList branchesgit checkout -b <name>Create and switch to a branchgit switch <name>Switch branchesgit merge <name>Merge a branch into currentRemotes
git remote -vList remotesgit pullFetch and merge from remotegit pushPush commits to remotegit push -u origin <branch>Push and set upstreamUndoing
git restore <file>Discard working changesgit reset --soft HEAD~1Undo last commit, keep changes stagedgit reset --hard HEAD~1Undo last commit and discard changesgit revert <hash>Create a commit that undoes anotherInspecting
git log --onelineCompact commit historygit diffUnstaged changesgit diff --stagedStaged changesgit show <hash>Show a commit