Menu

Git Cheat Sheet

Last updated

Setup & config

One-time setup so your commits are attributed correctly.

CommandWhat it does
git config --global user.name "Ada"Set your commit name
git config --global user.email you@x.comSet your commit email
git config --listShow all current config
git config --global init.defaultBranch mainName new repos' first branch main
git config --global core.editor "code --wait"Set your default editor
git --versionPrint the installed Git version

Creating & cloning

Start a new repository or copy an existing one.

CommandWhat it does
git initCreate a new repo in the current folder
git clone <url>Copy a remote repo locally
git clone <url> mydirClone into a named folder
git clone --depth 1 <url>Shallow clone (latest commit only)
git clone -b dev <url>Clone and check out the dev branch

Staging & committing

Record changes into the project history.

CommandWhat it does
git add file.txtStage one file
git add .Stage all changes in the current dir
git add -pStage selected chunks interactively
git commit -m "message"Commit staged changes
git commit -am "message"Stage tracked files and commit
git commit --amendEdit the last commit
git rm file.txtRemove a file and stage the deletion

Branching

Work on changes in isolation.

CommandWhat it does
git branchList local branches
git branch featureCreate a new branch
git switch featureSwitch to an existing branch
git switch -c featureCreate and switch in one step
git checkout featureOlder way to switch branches
git branch -d featureDelete a merged branch
git branch -m newnameRename the current branch

Merging & rebasing

Combine the work from two branches.

CommandWhat it does
git merge featureMerge feature into the current branch
git merge --no-ff featureAlways create a merge commit
git rebase mainReplay your commits on top of main
git rebase -i HEAD~3Interactively edit the last 3 commits
git rebase --continueResume after resolving conflicts
git rebase --abortCancel a rebase in progress
git cherry-pick <hash>Apply one commit onto this branch

Remotes (push, pull, fetch)

Sync your local repo with a remote like GitHub.

CommandWhat it does
git remote -vList configured remotes
git remote add origin <url>Link a remote named origin
git fetchDownload remote changes without merging
git pullFetch and merge the remote branch
git pushUpload commits to the remote
git push -u origin mainPush and set the upstream branch
git push origin --delete featureDelete a remote branch

Inspecting (status, log, diff)

See what changed and what is happening.

CommandWhat it does
git statusShow staged, unstaged, and untracked files
git logShow commit history
git log --oneline --graphCompact history with a branch graph
git diffUnstaged changes vs the index
git diff --stagedStaged changes vs the last commit
git show <hash>Show a single commit's changes
git blame file.txtShow who last changed each line

Undoing changes

Recover from mistakes safely.

CommandWhat it does
git restore file.txtDiscard unstaged changes to a file
git restore --staged file.txtUnstage a file (keep changes)
git reset --soft HEAD~1Undo last commit, keep changes staged
git reset --hard HEAD~1Undo last commit and discard changes
git revert <hash>Make a new commit that undoes another
git stashShelve changes for later
git stash popReapply the most recent stash

Every Git command you reach for, on one page. This Git cheat sheet is a quick reference for everyday version control - configuring Git, staging and committing, branching, merging and rebasing, syncing with remotes, and undoing mistakes.

These are standard Git commands that work the same on Linux, macOS, and Windows. Copy what you need, or try them live in the terminal playground - a real shell in your browser, nothing to install.

Git cheat sheet FAQ

Is this Git cheat sheet free?
Yes. This Git cheat sheet is completely free, with no sign-up required. Bookmark it and come back whenever you need to look up a command for branching, committing, or undoing changes.
What is the difference between merge and rebase?
git merge combines two branches by creating a new merge commit that ties their histories together, preserving the exact history of both. git rebase instead replays your commits one by one on top of another branch, producing a linear history with no merge commit. Merge is safe and non-destructive; rebase makes a cleaner history but rewrites commits, so avoid rebasing branches others have already pulled.
How do I undo a commit in Git?
It depends on whether you have pushed it. For a local commit, git reset --soft HEAD~1 undoes the last commit but keeps the changes staged, while git reset --hard HEAD~1 discards them entirely. For a commit that is already shared, use git revert <hash> to create a new commit that reverses it without rewriting history.
Can I practice Git commands online?
Yes. Open the terminal playground to run Git commands in a real shell in your browser - nothing to install. When you want structure, Coddy's free interactive Git course walks you from your first commit to branching, merging, and remotes step by step.
Is this cheat sheet good for beginners?
Yes. It is organized from setup and committing (the everyday basics) down to rebasing and undoing changes, so you can use the top sections on day one and grow into the advanced workflows.
Coddy programming languages illustration

Learn Git with Coddy

GET STARTED