Git Cheatsheet
The git commands developers reach for daily - from basic commits to untangling a messy branch.
Basics
git initCreate a new repository in the current folder
git clone <url>Clone a remote repository
git statusShow changed/staged files
git add <file>Stage a file for commit
git add .Stage all changed files
git commit -m "msg"Commit staged changes with a message
Branching
git branchList local branches
git branch <name>Create a new branch
git checkout <name>Switch to a branch
git checkout -b <name>Create and switch to a new branch
git merge <name>Merge a branch into the current one
git branch -d <name>Delete a local branch
Remote & sync
git push origin <branch>Push a branch to the remote
git pullFetch and merge from the remote
git fetchDownload remote changes without merging
git remote -vList configured remotes
Undoing things
git restore <file>Discard unstaged changes to a file
git restore --staged <file>Unstage a file (keep changes)
git reset --soft HEAD~1Undo last commit, keep changes staged
git reset --hard HEAD~1Undo last commit and discard changes
git revert <commit>Create a new commit that undoes a previous one
git stashTemporarily shelve uncommitted changes