Dev Utilities

Git Cheatsheet

Quick reference for essential Git commands — from initial setup and daily commits to branching, merging, rebasing and remote operations.

Open Git Cheatsheet →
Looks like you're using an ad blocker. Devbin is free — ads help keep it running.

Essential Git Commands

Setup & Init
git initInitialise a new Git repository in the current directory
git clone <url>Clone a remote repository locally
git config --global user.name "Name"Set your global commit author name
Stage & Commit
git statusShow working tree status — staged, unstaged and untracked files
git add <file>Stage a specific file for commit
git add -pInteractively stage hunks (partial file staging)
git commit -m "message"Create a commit with a message
git commit --amendModify the most recent commit (message or staged files)
Branches
git branchList all local branches
git checkout -b <branch>Create and switch to a new branch
git switch <branch>Switch to an existing branch (modern syntax)
git merge <branch>Merge a branch into the current branch
git rebase <branch>Rebase current branch onto another
git branch -d <branch>Delete a local branch (safe — only if merged)
Remote
git fetchDownload remote changes without merging
git pullFetch and merge remote changes (fetch + merge)
git push origin <branch>Push local branch to remote
git push -u origin <branch>Push and set upstream tracking
Undo & Stash
git stashStash uncommitted changes temporarily
git stash popRestore the most recent stash
git reset --soft HEAD~1Undo last commit, keep changes staged
git restore <file>Discard unstaged changes in a file
git log --onelineShow compact commit history

Frequently Asked Questions

merge vs rebase?
git merge combines branches with a merge commit, preserving full history. git rebase replays commits for a linear history. Use merge for public branches; rebase for local cleanup.
What does git stash do?
Saves uncommitted changes temporarily so you can switch branches cleanly. git stash pop restores them later. git stash list shows all stashes.
fetch vs pull?
git fetch downloads changes but does not apply them. git pull = fetch + merge. Fetch first to review what changed before merging.
How do I undo the last commit?
git reset --soft HEAD~1 — keeps changes staged. git reset HEAD~1 — unstages. git reset --hard HEAD~1 — discards all changes (destructive).

Open the Git Cheatsheet now

Browse all Git commands with descriptions and copy any command directly — free, no login required.

Open Git Cheatsheet →