# Git Command Cheat Sheet - Undo, Branch, Rebase, Stash

> Free Git cheat sheet: 60+ commands grouped by what you want to do — undo, branch, rebase, remotes, history, stash, cleanup — with copy and danger warnings.

- URL: https://qilingtools.com/en/git-commands
- Category: Developer Tools (https://qilingtools.com/en/dev)
- Tags: [Developer](https://qilingtools.com/en/tags/dev), [DevOps](https://qilingtools.com/en/tags/devops)
- Last updated: 2026-10-26
- Price: Free, no sign-up
- Privacy: Runs locally in the browser; files are never uploaded

Git is hard not because there are many commands but because the thing you want rarely matches the command name: to undo the last commit, is it reset, revert or restore? So this sheet is grouped by situation — undo and recovery, everyday commits, branches and rebase, remotes, investigating history, stashing, cleanup, configuration. Each entry says what it does and whether it throws work away.

## How to use

1. Search by situation (undo, force push) or by command (rebase)
2. Browse by group — start with undo and recovery
3. Click a command to copy it, then replace anything in angle brackets

## Features

- 60+ commands grouped by use rather than alphabetically
- Destructive commands flagged in red so you know what disappears
- Uses the modern forms: switch and restore instead of the overloaded checkout
- Pushes --force-with-lease over --force, and reflog as the universal undo

## FAQ

### Which command actually undoes a commit?

Not pushed yet: git reset --soft HEAD~1 keeps the changes staged. Already pushed and others may have pulled: git revert <commit> adds an inverse commit without rewriting history. Just want to drop a file's changes: git restore <file>.

### I reset away a commit — can I get it back?

Almost always. git reflog lists every move of HEAD (kept for 90 days); find the SHA and run git reset --hard <sha> or git switch -c rescue <sha>. The objects are still there unless you ran git gc --prune=now.

### Merge or rebase?

Merge into shared branches to keep the real history; rebase your own feature branch onto the trunk for a linear story. One rule: never rebase commits other people have already pulled.

### What is the difference between --force and --force-with-lease?

--force overwrites the remote branch unconditionally, so a colleague's fresh commits vanish. --force-with-lease first checks the remote is still where you last saw it and refuses otherwise. Make the second one your habit.

## Related tools

- [JSON Formatter](https://qilingtools.com/en/json): Free online JSON formatter: beautify or minify, validate with the exact line and column of any error, browse a collapsible tree, sort keys and escape strings.
- [Base64 Encode/Decode](https://qilingtools.com/en/base64): Free online Base64 encoder and decoder: UTF-8 safe, optional URL-safe variant, convert text to Base64 and back in real time. Processed locally, never uploaded.
- [URL Encode/Decode](https://qilingtools.com/en/url-encode): Free online URL encoder and decoder with encodeURIComponent and encodeURI modes. Escapes Chinese, spaces and special characters. Real-time and local, no upload.
- [JWT Decoder](https://qilingtools.com/en/jwt): Free online JWT decoder: decode the header and payload of a JSON Web Token, show expiry and issued-at times, all locally without uploading the token.
- [Timestamp Converter](https://qilingtools.com/en/timestamp): Free online Unix timestamp converter: convert timestamps and dates, auto-detect seconds or milliseconds, and show local, UTC, ISO 8601 and relative time.
- [Hash / Checksum](https://qilingtools.com/en/hash): Free online hash calculator: SHA-1, SHA-256, SHA-384 and SHA-512 of text or any file through the browser crypto API. Files never leave your device.
- [UUID Generator](https://qilingtools.com/en/uuid): Free online UUID generator: create RFC 4122 UUID v4 in bulk with a cryptographic RNG. Options for uppercase, no hyphens and braces, with one-click copy.
- [Base Converter](https://qilingtools.com/en/base-convert): Free online number base converter: convert between binary, octal, decimal, hexadecimal and any base 2–36. Uses BigInt for huge integers, computed locally.
