Git commands cheatsheet.
The Git commands you reach for daily — staging, branching, syncing and undoing. Tap any command to copy it.
git initCreate a new Git repository in the current foldergit clone <url>Copy a remote repository to your machinegit config --global user.name "Name"Set the name attached to your commitsgit config --global user.email "you@example.com"Set the email attached to your commitsgit statusShow changed, staged and untracked filesgit add <file>Stage a specific file for the next commitgit add .Stage all changes in the current foldergit commit -m "message"Commit staged changes with a messagegit commit -am "message"Stage tracked files and commit in one stepgit restore <file>Discard uncommitted changes to a filegit reset <file>Unstage a file but keep its changesgit branchList local branchesgit switch -c <name>Create a new branch and switch to itgit switch <name>Switch to an existing branchgit merge <name>Merge another branch into the current onegit branch -d <name>Delete a merged branchgit rebase <name>Reapply commits on top of another branchgit remote -vShow configured remote repositoriesgit remote add origin <url>Connect a local repo to a remotegit pushUpload commits to the remotegit push -u origin <branch>Push and set the upstream branchgit pullFetch and merge changes from the remotegit fetchDownload remote changes without merginggit log --onelineShow a compact commit historygit diffShow unstaged changes line by linegit stashShelve uncommitted changes for latergit stash popReapply the most recently stashed changesgit revert <commit>Create a new commit that undoes a commitgit reset --hard <commit>Reset the branch and working tree to a commitgit cherry-pick <commit>Apply a specific commit onto the current branchThe handful of commands you'll use constantly
Git has hundreds of options, but day-to-day work runs on a small core. You check what's changed with git status, stage the changes you want with git add, record them with git commit -m "message", and share them with git push. To bring in others' work you use git pull. If you do nothing else, getting fluent with this loop covers the large majority of real Git usage. Everything else on this page is for the moments that loop isn't enough.
Branching is where Git earns its keep
Branches let you work on something without disturbing the main line of code. Create and switch to one with git switch -c feature-name, commit freely, then merge it back with git merge once it's ready. The mental model that helps most beginners: a branch is just a movable label pointing at a commit, and switching branches changes which version of the files you see. Keeping each piece of work on its own branch keeps your history readable and makes collaborating far less stressful.
Undoing things without panic
The commands people fear most are the undo ones, usually because the wrong choice can lose work. The safe rule of thumb: use git revert to undo a commit that others may already have (it adds a new commit that reverses the old one, changing nothing about history), and reserve git reset --hard for local commits no one else has seen, because it genuinely discards changes. git stash is the unsung hero here — it shelves your uncommitted work so you can switch tasks, then git stash pop brings it back.
Tips that prevent headaches
Commit in small, logical chunks with clear messages — your future self reads them constantly. Run git status before every commit so you know exactly what you're including. Pull before you start work to reduce merge conflicts. And when something looks scary, remember that committed work in Git is remarkably hard to truly lose. Pair these with the VS Code shortcuts for editing and the terminal commands for navigating your project, and you've got the core developer workflow covered.