Git Commands

Git commands cheatsheet.

The Git commands you reach for daily — staging, branching, syncing and undoing. Tap any command to copy it.

Setup & config
git initCreate a new Git repository in the current folder
git clone <url>Copy a remote repository to your machine
git config --global user.name "Name"Set the name attached to your commits
git config --global user.email "you@example.com"Set the email attached to your commits
Staging & committing
git statusShow changed, staged and untracked files
git add <file>Stage a specific file for the next commit
git add .Stage all changes in the current folder
git commit -m "message"Commit staged changes with a message
git commit -am "message"Stage tracked files and commit in one step
git restore <file>Discard uncommitted changes to a file
git reset <file>Unstage a file but keep its changes
Branches & merging
git branchList local branches
git switch -c <name>Create a new branch and switch to it
git switch <name>Switch to an existing branch
git merge <name>Merge another branch into the current one
git branch -d <name>Delete a merged branch
git rebase <name>Reapply commits on top of another branch
Remote & sync
git remote -vShow configured remote repositories
git remote add origin <url>Connect a local repo to a remote
git pushUpload commits to the remote
git push -u origin <branch>Push and set the upstream branch
git pullFetch and merge changes from the remote
git fetchDownload remote changes without merging
History & undo
git log --onelineShow a compact commit history
git diffShow unstaged changes line by line
git stashShelve uncommitted changes for later
git stash popReapply the most recently stashed changes
git revert <commit>Create a new commit that undoes a commit
git reset --hard <commit>Reset the branch and working tree to a commit
git cherry-pick <commit>Apply a specific commit onto the current branch

Everyday Git, in one place

Most Git work comes down to a handful of commands: git status, git add, git commit, and git push. This cheatsheet groups those with the branching, syncing and undo commands you reach for less often but always forget — like git stash, git revert and git rebase. Click any command to copy it.

FAQ

How do I undo the last Git commit?
Use git revert to create a new commit that undoes it (safe for shared history), or git reset --hard to move the branch back and discard changes (only on local, unshared work).
What's the difference between git switch and git checkout?
git switch is the newer, clearer command for changing branches (git switch -c creates one), while git checkout does that plus file restoring. Both work; switch is recommended for branches.

More cheatsheets