glunty

Git Command Cheat Sheet

A searchable reference of common git commands and what each one does.

Common git commands with a plain-English description of what each one does
Command What it does
git init Create a new empty git repository in the current directory.
git clone <url> Copy a remote repository with its full history into a new local folder.
git clone <url> <dir> Clone a remote repository into a named local folder.
git config --global user.name "Your Name" Set the author name recorded on your commits in every repository.
git config --global user.email "you@example.com" Set the author email recorded on your commits in every repository.
git config --global init.defaultBranch main Make new repositories start on a branch named main.
git config --list List every effective setting and the config file it comes from.
git status Show which files are staged, modified, or untracked.
git status -s Show a compact short-format status.
git add <file> Stage a file so its current changes go into the next commit.
git add . Stage all changes in the current directory and below.
git add -A Stage every change in the working tree, including deletions.
git add -p Interactively pick which chunks of a file to stage.
git restore --staged <file> Unstage a file while keeping its working-tree changes.
git rm <file> Delete a file and stage its removal.
git mv <old> <new> Rename or move a file and stage the change.
git commit -m "message" Record the staged changes with an inline message.
git commit -a -m "message" Stage all tracked modified files and commit in one step.
git commit --amend Replace the last commit with the staged changes and an edited message.
git branch List local branches and mark the current one.
git branch -a List local and remote-tracking branches.
git branch <name> Create a branch at the current commit without switching to it.
git switch <name> Switch to an existing branch (modern, safer than checkout).
git switch -c <name> Create a new branch and switch to it.
git checkout <name> Switch to an existing branch (older command).
git checkout -b <name> Create a new branch and switch to it (older command).
git branch -d <name> Delete a branch that is already merged.
git branch -m <old> <new> Rename a branch.
git merge <branch> Combine the named branch into the current one, adding a merge commit if needed.
git merge --no-ff <branch> Merge and always create a merge commit so the branch history stays visible.
git merge --abort Cancel an in-progress merge and return to the pre-merge state.
git rebase <branch> Replay your commits on top of the named branch for a linear history.
git rebase -i <base> Interactively reorder, squash, edit, or drop commits back to a base.
git rebase --continue Resume a rebase after resolving the conflicts in the current step.
git rebase --abort Stop a rebase and restore the branch to its original state.
git cherry-pick <commit> Apply the changes from a specific commit onto the current branch.
git remote -v List remote names with their fetch and push URLs.
git remote add <name> <url> Add a new remote repository under a short name.
git remote set-url <name> <url> Change the URL an existing remote points to.
git fetch Download new commits and refs from the remote without touching your files.
git fetch --prune Fetch and drop local refs to remote branches that no longer exist.
git pull Fetch from the remote and merge the tracked branch into the current one.
git push Send your committed changes to the remote tracking branch.
git push -u <remote> <branch> Push and set the upstream so later pushes need no arguments.
git push --force-with-lease Overwrite the remote only if no one pushed since your last fetch, which is safer than --force.
git restore <file> Discard unstaged changes in a file back to the last commit.
git restore --staged <file> Unstage a file while keeping its changes.
git checkout -- <file> Discard changes in a file (older equivalent of git restore).
git reset <file> Unstage a file, keeping its working-tree changes.
git reset --soft HEAD~1 Undo the last commit but keep its changes staged.
git reset --hard HEAD~1 Undo the last commit and permanently discard its changes (destructive).
git revert <commit> Add a new commit that undoes a past commit without rewriting history.
git clean -fd Delete untracked files and directories (destructive; preview with -n first).
git reflog Show where HEAD has pointed over time so you can recover lost commits.
git log Show the commit history with author, date, and message.
git log --oneline Show one compact line per commit.
git log --oneline --graph Draw an ASCII branch graph beside compact commit lines.
git diff Show unstaged changes between the working tree and the index.
git diff --staged Show staged changes that will go into the next commit.
git show <commit> Show the metadata and diff of a single commit.
git blame <file> Show who last changed each line of a file and in which commit.
git shortlog -sn Summarize commit counts per author.
git stash Save uncommitted changes aside and revert the working tree to a clean state.
git stash -u Stash your changes including untracked files.
git stash list List all stashes you have saved.
git stash show -p Show the diff of the most recent stash.
git stash pop Reapply the most recent stash and remove it from the list.
git stash apply Reapply the most recent stash but keep it in the list.
git stash drop Delete the most recent stash.

Runs entirely in your browser. Nothing you type is sent anywhere; open DevTools and watch the Network tab to verify zero requests.

What this tool does

This is a searchable quick reference for the git commands you reach for every day, from setting up a repository to staging, branching, merging, syncing with a remote, and cleaning up mistakes. Each row pairs the exact command with a plain-English note on what it does. Type in the filter box to search across both columns, or tap a category button to focus on one workflow. The whole list is built into the page, so it works offline and sends nothing anywhere.

How to use it

Start typing in the Filter box. Entering amend jumps straight to git commit --amend; entering undo or reset surfaces the recovery commands; entering push shows every way to send work to a remote. The category buttons (Setup, Stage and commit, Branch, Merge and rebase, Remote, Undo, Inspect, Stash) narrow the table to one family and combine with the text filter, so you can pick Undo and type hard to zero in on the destructive resets. Clear the box to see the full sheet again.

Common use cases

  • Recalling the exact flags for a command you use rarely, like git rebase -i or git reset --soft.
  • Copying a safe command into your terminal instead of guessing and risking data loss.
  • Teaching a teammate the difference between reset, revert, and restore.
  • Finding the safer alternative to a dangerous command, such as --force-with-lease instead of --force.
  • Reviewing the core git workflow before an interview or a new job.

Common pitfalls

  • Force-pushing over a teammate. A plain git push --force can erase commits someone else pushed. Prefer git push --force-with-lease, which refuses the push if the remote moved since your last fetch.
  • Rebasing a shared branch. Rebasing rewrites commit identities, so anyone who already pulled the branch ends up with a tangled, conflicting history. Only rebase commits that still live on your machine.
  • Detached HEAD. Checking out a specific commit rather than a branch leaves you in a detached HEAD state, where new commits belong to no branch and can be lost. Create a branch with git switch -c before committing.
  • Committing to the wrong branch. It is easy to commit while on main by accident. Check git status or your shell prompt first; if it happens, move the work with git switch and git cherry-pick, then clean up with git reset --soft.

Frequently asked questions

What is the difference between git reset and git revert?
git reset moves your branch pointer to an earlier commit, so it rewrites history and can drop later commits; it is best on commits you have not shared yet. git revert instead adds a new commit that undoes the changes of an earlier one, leaving the original history intact. Use revert on shared branches because it does not force anyone else to rewrite their copy.
What does git push --force-with-lease do and why prefer it over --force?
A plain --force overwrites the remote branch no matter what, so it can silently erase commits a teammate pushed while you were working. --force-with-lease first checks that the remote still points where you last saw it, and refuses the push if someone else has added commits. It gives you the power of a force push while protecting other people from lost work.
What is the difference between git merge and git rebase?
git merge joins two branches with a merge commit, preserving the exact record of what happened and when. git rebase instead replays your commits on top of another branch, producing a straight, linear history with no merge commit. Merge is safer for shared branches, while rebase makes for a cleaner log but rewrites commit identities, so avoid it on branches others already pulled.
How do I undo the last commit?
If you have not pushed yet, run git reset --soft HEAD~1 to remove the commit but keep its changes staged, or git reset --hard HEAD~1 to discard the changes entirely. To just fix the message or add a forgotten file, use git commit --amend. If the commit is already shared, prefer git revert so you do not rewrite public history.
What is the git reflog?
The reflog is a local log of every position HEAD has held, including commits that are no longer on any branch. When a reset, rebase, or bad merge seems to have lost work, git reflog usually still lists the commit you want, and you can recover it with git checkout or git reset to that entry. It is a safety net, though entries expire after a while and are never pushed to a remote.
What is the difference between git fetch and git pull?
git fetch downloads new commits and refs from the remote but leaves your working branch untouched, so you can inspect what changed before integrating it. git pull runs a fetch and then immediately merges or rebases those changes into your current branch. Pull is faster for routine updates, while fetching first is safer when you want to review incoming work.
Does this cheat sheet run offline or send my searches anywhere?
It runs fully offline. The entire command list is baked into the page and all filtering happens in your browser with JavaScript, so nothing you type is sent to any server. Open your browser DevTools and watch the Network tab while you search to confirm there are zero requests.

Embed this tool

Free for any use; attribution appreciated. Paste this on your site:

The embed runs the same tool that lives at this URL. No tracking; no ads inside the embed. Resize height as needed for your layout.

Cite this tool

For academic, journalistic, or technical references. Pick a format:

Citations use 2026 as the publication year. Access date is left as a fillable placeholder where the citation style expects one.

Embedded tool from glunty.com