Git 7 🧩 Git Cheatsheet
A single-page reference for the Git commands you’ll reach for most. Grouped by task, with a short description of what each does. Bookmark it — you’ll come back often.
Key point: This isn’t a tutorial — it’s a lookup table. When you know what you want but not the exact syntax, find the command here.
a. Part 1: Basic & Everyday Commands
The commands you’ll type every day. Start here.
| Command | Description |
|---|---|
git init | Initializes a new local Git repository. |
git clone [url] | Creates a local copy of a remote repository. |
git status | Shows the status of changes as untracked, modified, or staged. |
git add . | Stages all changes in the current directory for the next commit. |
git add [file] | Stages a specific file for the next commit. |
git commit -m "[message]" | Records staged changes to the repository with a descriptive message. |
git push | Pushes committed changes to a remote repository. |
git pull | Fetches and merges changes from the remote repository. |
The daily loop: status → add → commit → push. Pull before starting. Check status often.
b. Part 2: Branching & Merging
Branches isolate work. Merge brings it back.
| Command | Description |
|---|---|
git branch | Lists all local branches. |
git branch [name] | Creates a new branch. |
git checkout [name] | Switches to a different branch. |
git checkout -b [name] | Creates and switches to a new branch. |
git merge [branch] | Merges the specified branch’s history into the current branch. |
git branch -d [name] | Deletes a local branch. |
git fetch | Downloads objects and refs from another repository. It does not merge changes, leaving them for you to inspect. |
git rebase [target] | Reapplies commits from the current branch on top of another branch, creating a cleaner, linear history. |
Modern alternatives: git switch [name] and git switch -c [name] replace the checkout forms when changing branches — clearer intent, same effect.
When to use which:
- Merge — for shared branches, preserves history
- Rebase — for private branches, produces linear history
Never rebase a shared branch. Use merge there instead.
c. Part 3: Undoing & Rewriting History
Getting out of trouble. Read the cautions.
| Command | Description |
|---|---|
git reset [file] | Unstages a file without changing its content. |
git reset --hard | Discards all changes in the working directory and staging area, and moves HEAD to the specified commit. Caution: This is destructive. |
git checkout -- [file] | Discards changes in a working directory. Caution: This is destructive. |
git revert [commit] | Creates a new commit that undoes the changes from a previous commit. This is a safer way to “undo” a commit as it doesn’t rewrite history. |
git commit --amend | Amends the last commit, useful for adding forgotten files or correcting the commit message. |
git rebase -i [commit] | Opens an interactive rebase editor, allowing you to squash, reorder, or drop commits. Caution: Do not use this on public branches. |
The safety hierarchy:
| Command | Destructive? | Rewrites history? |
|---|---|---|
git revert | ❌ | ❌ |
git commit --amend | ⚠️ | ✅ (last commit only) |
git reset --soft | ❌ | ✅ |
git reset --mixed | ⚠️ (unstages) | ✅ |
git reset --hard | ✅ | ✅ |
Rule of thumb: If the commit is already pushed and others may have it, use git revert. Never rewrite shared history.
Modern alternative: git restore [file] replaces git checkout -- [file] for discarding working-directory changes. Clearer intent.
d. Part 4: Remote Repositories & Collaboration
Working with remotes.
| Command | Description |
|---|---|
git remote -v | Lists the remote repositories you are connected to. |
git remote add [name] [url] | Adds a new remote repository. |
git remote rm [name] | Removes a remote repository. |
git fetch [remote] | Fetches all branches from the remote repository. |
git pull --rebase | Pulls changes from the remote and rebases them on top of your local commits, creating a cleaner history. |
Common remote names:
| Name | Meaning |
|---|---|
origin | Your primary remote (fork or clone source) |
upstream | The original repo you forked from |
Why pull --rebase: Regular git pull creates a merge commit every time you pull with local changes. --rebase replays your local commits on top, keeping history linear.
e. Part 5: Tagging & Inspection
Looking at history. Marking releases.
| Command | Description |
|---|---|
git log | Shows the commit history. |
git log --oneline | Shows a condensed, one-line view of the commit history. |
git show [commit] | Shows the changes for a specific commit. |
git diff | Shows changes in the working directory that are not yet staged. |
git diff --staged | Shows changes in the staging area that are not yet committed. |
git tag [name] | Creates a lightweight tag at the current commit. |
git tag -a [name] -m "[message]" | Creates an annotated tag with a message. |
Useful git log variants:
| Command | Shows |
|---|---|
git log --oneline --graph --all | Visual branch graph |
git log -n 5 | Last 5 commits |
git log --author="name" | Commits by author |
git log --since="2 weeks ago" | Recent commits |
git log --grep="pattern" | Commits matching a message |
Tag types:
| Type | When to use |
|---|---|
Lightweight (git tag name) | Personal markers |
Annotated (git tag -a) | Releases |
Quick Reference
Daily Commands
| Task | Command |
|---|---|
| Check status | git status |
| Stage all | git add . |
| Stage one | git add file |
| Commit | git commit -m "msg" |
| Push | git push |
| Pull | git pull |
Branching
| Task | Command |
|---|---|
| List branches | git branch |
| Create branch | git branch name |
| Switch | git switch name |
| Create + switch | git switch -c name |
| Merge | git merge name |
| Delete | git branch -d name |
| Rebase | git rebase target |
Undoing
| Task | Command |
|---|---|
| Unstage file | git reset file |
| Discard changes | git restore file |
| Undo last commit (keep changes) | git reset --soft HEAD~1 |
| Undo last commit (discard) | git reset --hard HEAD~1 |
| Revert a commit | git revert commit |
| Amend last commit | git commit --amend |
| Interactive rebase | git rebase -i HEAD~N |
Remotes
| Task | Command |
|---|---|
| List remotes | git remote -v |
| Add remote | git remote add name url |
| Remove remote | git remote rm name |
| Fetch | git fetch origin |
| Pull with rebase | git pull --rebase |
Inspection
| Task | Command |
|---|---|
| Full log | git log |
| One-line log | git log --oneline |
| Visual graph | git log --oneline --graph --all |
| Show a commit | git show commit |
| Unstaged diff | git diff |
| Staged diff | git diff --staged |
Tags
| Task | Command |
|---|---|
| Lightweight tag | git tag name |
| Annotated tag | git tag -a name -m "msg" |
| List tags | git tag |
| Push tags | git push origin --tags |
| Delete local | git tag -d name |
| Delete remote | git push origin --delete name |
Best Practices (Quick Reminder)
✅ Do:
git statusbefore every commitgit pull --rebaseto keep history clean- Commit small, focused changes
- Use branches for everything
- Read
git diff --stagedbefore committing - Push often — local work isn’t backup
❌ Don’t:
- Commit secrets
- Rewrite pushed history
- Force-push shared branches
- Commit without a message
- Use
--hardcasually - Rebase public branches
Summary
| Group | Purpose |
|---|---|
| Basic | Daily commands |
| Branching | Isolate and merge work |
| Undoing | Recover from mistakes |
| Remotes | Collaborate |
| Inspection | Read history |
| Tags | Mark releases |
Key takeaways:
- Daily loop: status → add → commit → push
- Branches isolate work; merge integrates it
- Rebase rewrites history — private branches only
- Revert undoes safely without rewriting
- Reset –hard is destructive — use with care
- Remotes connect local and shared work
git diff --stagedshows what’s about to be committed- Tags mark releases — annotated for public, lightweight for personal
git log --oneline --graph --allshows the whole picture
Remember: This is a reference, not a curriculum. When you know the goal but not the syntax, come here. When you’re not sure what a command does, run git help <command> or read its section in this series. And when in doubt — before anything destructive — run git status, and consider whether you can undo it.
Stop using slow, ad-bloated tool sites! 🤮
🔎 Search “KandZ Tools” on Google to use many professional utilities for free.
KandZ.me is the ultimate minimalist hub for:
✅ Finance (Mortgage, Interest, Inflation)
✅ Tech (Base64, JSON, Dev Suite, IP)
✅ Health (BMI, BMR, TDEE)
✅ Productivity (Timer, Workspace, QR)
⚡️ Fast & Private
🔒 No data leaves your device
💎 100% Free
🔗 Use it now: https://tools.kandz.me
🔖 Bookmark it—you’ll need it later!