Git Command Reference

A searchable cheatsheet — or describe your situation and get the exact fix.

Runs in your browserNo sign-up required
Basics
git init

Create a new, empty Git repository in the current folder.

git clone <url>

Copy a remote repository to your local machine.

git status

Show which files are staged, unstaged, or untracked.

git add <file>

Stage a file's changes for the next commit. Use `git add .` to stage everything.

git commit -m "message"

Save staged changes as a new commit with a message.

git log

Show commit history. Add `--oneline` for a compact one-line-per-commit view.

git diff

Show unstaged changes, line by line. Add `--staged` to see staged changes instead.

Branching & Merging
git branch

List local branches. Add a name to create a new one: `git branch feature-x`.

git checkout <branch>

Switch to an existing branch.

git checkout -b <branch>

Create a new branch and switch to it in one step.

git switch <branch>

The newer, dedicated command for switching branches (Git 2.23+).

git merge <branch>

Merge the named branch into your current branch.

git branch -d <branch>

Delete a branch that's already been merged. Use `-D` to force-delete an unmerged one.

git rebase <branch>

Replay your current branch's commits on top of another branch, producing a linear history.

Undoing Changes
git restore <file>

Discard unstaged changes to a file, reverting it to the last commit.

git restore --staged <file>

Unstage a file without discarding its changes.

git reset --soft HEAD~1

Undo the last commit, keeping its changes staged.

git reset --mixed HEAD~1

Undo the last commit, keeping its changes but unstaged (the default reset mode).

git reset --hard HEAD~1

Undo the last commit and permanently discard its changes. Destructive — use with care.

git revert <commit>

Create a new commit that undoes a specific past commit, without rewriting history.

git commit --amend

Modify the most recent commit — its message, or add more staged changes to it.

Stashing
git stash

Temporarily shelve uncommitted changes so you can switch branches cleanly.

git stash -u

Stash changes including untracked files (not just modified ones).

git stash list

Show all stashed change sets.

git stash pop

Reapply the most recent stash and remove it from the stash list.

git stash apply

Reapply the most recent stash but keep it in the stash list.

git stash drop

Delete a stash without applying it.

Remote & Syncing
git remote -v

List configured remotes and their URLs.

git fetch

Download commits and branches from a remote, without merging them into your work.

git pull

Fetch and immediately merge the remote branch into your current branch.

git push

Upload your local commits to the remote branch.

git push -u origin <branch>

Push a new branch and set it to track the remote branch for future pushes/pulls.

git push --force-with-lease

Force-push safely — fails if someone else pushed changes you haven't seen yet, unlike plain --force.

Inspecting History
git show <commit>

Show the full diff and metadata for a single commit.

git blame <file>

Show which commit last modified each line of a file.

git log --graph --oneline --all

Show a visual, compact graph of all branches' commit history.

git reflog

Show a log of everywhere HEAD has pointed — the safety net for recovering "lost" commits.

Two Ways to Find What You Need

Browse Commands is a categorized, searchable list — branching, undoing changes, stashing, syncing with a remote — with a plain-English explanation for each one. "What do I need to do X" flips that around: describe the situation you're actually in ("I committed to the wrong branch," "I have a merge conflict") and get the specific command sequence to resolve it, in the right order, rather than having to assemble it yourself from separate references.

Frequently Asked Questions

How is the "What do I need to do X" mode different from just searching commands?

Most of the time you don't arrive at Git documentation wanting to browse — you have a specific problem, like having committed to the wrong branch. This mode lets you describe that situation directly and get the exact command sequence to fix it, in order, instead of having to piece it together from separate command descriptions yourself.

Are these commands safe to run?

Most are, but a few (git reset --hard, git push --force, git clean -fd) permanently discard work if used carelessly — those are called out specifically in their descriptions. When in doubt, commit or stash your current work first.

Does this cover every Git command?

No — it's focused on the commands developers reach for constantly: staging, committing, branching, merging, undoing mistakes, stashing, and syncing with a remote. For a full command reference, Git's own `git help <command>` is the authoritative source.

Is my situation description sent anywhere?

No — the search and matching happen entirely in your browser against a fixed local list. Nothing you type here is transmitted anywhere.