RUNWEBTOOLS
English

Git Commands Cheat Sheet: The Commands You Actually Use

Git has hundreds of commands, but day-to-day work runs on a couple of dozen. This is that practical set — grouped by task, from staging and committing to branching, remotes, and undoing mistakes. Angle brackets <like this> mark a value you fill in.

Updated 2026-07-06

Setup

CommandWhat it does
git initStart a new repository in the current folder
git clone <url>Copy a remote repository to your machine
git config --global user.name "Name"Set your commit author name
git config --global user.email "you@x.com"Set your commit author email

Staging & committing

CommandWhat it does
git statusShow changed, staged, and untracked files
git add <file>Stage a file for the next commit
git add .Stage all changes in the current folder
git reset <file>Unstage a file (keep the changes)
git commit -m "message"Commit staged changes with a message
git commit -am "message"Stage tracked files and commit in one step
git commit --amendEdit the most recent commit

Branching

CommandWhat it does
git branchList local branches
git branch <name>Create a new branch
git checkout <name>Switch to a branch
git switch <name>Switch to a branch (newer syntax)
git checkout -b <name>Create and switch to a new branch
git branch -d <name>Delete a merged branch
git branch -D <name>Force-delete a branch

Merging & rebasing

CommandWhat it does
git merge <branch>Merge a branch into the current one
git rebase <branch>Replay your commits on top of another branch
git rebase -i <ref>Interactively edit, squash, or reorder commits
git cherry-pick <hash>Apply a single commit onto the current branch

Remotes

CommandWhat it does
git remote -vList configured remotes
git remote add origin <url>Connect a local repo to a remote
git fetchDownload remote changes without merging
git pullFetch and merge remote changes
git pushUpload your commits to the remote
git push -u origin <branch>Push and set the upstream branch

Undoing things

CommandWhat it does
git restore <file>Discard uncommitted changes to a file
git reset --soft HEAD~1Undo the last commit, keep changes staged
git reset --hard HEAD~1Undo the last commit and discard changes
git revert <hash>Create a new commit that undoes a commit
git stashShelve changes to work on something else
git stash popReapply the most recently stashed changes

Inspecting history

CommandWhat it does
git logShow the commit history
git log --onelineCompact one-line-per-commit history
git diffShow unstaged changes
git diff --stagedShow staged changes
git show <hash>Show the details of a specific commit
git blame <file>Show who last changed each line