Git Cheatsheet

Quick reference for the most common Git commands. Search and copy with one click.

Setup & Config

CommandDescription
git config --global user.name "Name"Set global username
git config --global user.email "email"Set global email
git config --listList all configuration settings
git config --global core.editor "code --wait"Set VS Code as default editor
git config --global alias.st statusCreate a git alias

Creating Repos

CommandDescription
git initInitialize a new local repository
git init <directory>Initialize in a specific directory
git clone <url>Clone a remote repository
git clone <url> <directory>Clone into a specific folder
git clone --depth 1 <url>Shallow clone (latest snapshot only)

Basic Workflow

CommandDescription
git statusShow working tree status
git add <file>Stage a specific file
git add .Stage all changes
git add -pInteractively stage hunks
git commit -m "message"Commit with a message
git commit --amendAmend the last commit
git diffShow unstaged changes
git diff --stagedShow staged changes
git rm <file>Remove a file from tracking
git mv <old> <new>Move or rename a file

Branching

CommandDescription
git branchList local branches
git branch -aList all branches (local + remote)
git branch <name>Create a new branch
git checkout <branch>Switch to a branch
git checkout -b <branch>Create and switch to a new branch
git switch <branch>Switch to a branch (modern)
git switch -c <branch>Create and switch (modern)
git branch -d <branch>Delete a merged branch
git branch -D <branch>Force-delete a branch
git branch -m <old> <new>Rename a branch

Merging

CommandDescription
git merge <branch>Merge branch into current branch
git merge --no-ff <branch>Merge with a merge commit (no fast-forward)
git merge --squash <branch>Squash all commits into one before merging
git merge --abortAbort an in-progress merge
git rebase <branch>Rebase current branch onto another
git rebase -i HEAD~<n>Interactive rebase last N commits
git rebase --abortAbort an in-progress rebase
git cherry-pick <commit>Apply a specific commit to current branch

Stashing

CommandDescription
git stashStash current changes
git stash push -m "message"Stash with a description
git stash listList all stashes
git stash popApply and remove the latest stash
git stash apply stash@{n}Apply a specific stash
git stash drop stash@{n}Delete a specific stash
git stash clearRemove all stashes
git stash branch <branch>Create branch from stash

Undoing

CommandDescription
git restore <file>Discard changes in working directory
git restore --staged <file>Unstage a file
git reset HEAD~1Undo last commit (keep changes staged)
git reset --soft HEAD~1Undo last commit (keep changes staged)
git reset --hard HEAD~1Undo last commit (discard changes)
git revert <commit>Create a new commit that undoes a commit
git clean -fdRemove untracked files and directories
git reflogShow history of HEAD movements

Remote

CommandDescription
git remote -vList remotes with URLs
git remote add origin <url>Add a remote named origin
git remote remove <name>Remove a remote
git fetchFetch all remotes
git fetch <remote>Fetch a specific remote
git pullFetch and merge from remote
git pull --rebaseFetch and rebase onto remote
git pushPush to tracking remote branch
git push -u origin <branch>Push and set upstream
git push --force-with-leaseForce push (safe version)
git push origin --delete <branch>Delete a remote branch

Log & Diff

CommandDescription
git logShow commit history
git log --onelineCompact one-line log
git log --oneline --graph --allVisual branch graph
git log -pShow commits with patches
git log --author="name"Filter by author
git log --since="2 weeks ago"Filter by date
git log --grep="keyword"Search commit messages
git diff <branch1>..<branch2>Diff between two branches
git show <commit>Show a specific commit
git blame <file>Show who changed each line
git shortlog -snSummarize commits by author

FAQ

Is Git Cheatsheet free to use?

Yes, Git Cheatsheet is completely free to use on UtilityCove.

Does Git Cheatsheet upload my data?

No. Git Cheatsheet runs in your browser, so your input stays on your device.

Can I use Git Cheatsheet on mobile?

Yes. Git Cheatsheet works on modern mobile and desktop browsers.