| |

Git 7 🧩 Git Cheatsheet

⏱️ Estimated read: 6 min | |

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.

CommandDescription
git initInitializes a new local Git repository.
git clone [url]Creates a local copy of a remote repository.
git statusShows 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 pushPushes committed changes to a remote repository.
git pullFetches 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.

CommandDescription
git branchLists 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 fetchDownloads 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.

CommandDescription
git reset [file]Unstages a file without changing its content.
git reset --hardDiscards 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 --amendAmends 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:

CommandDestructive?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.

CommandDescription
git remote -vLists 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 --rebasePulls changes from the remote and rebases them on top of your local commits, creating a cleaner history.

Common remote names:

NameMeaning
originYour primary remote (fork or clone source)
upstreamThe 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.

CommandDescription
git logShows the commit history.
git log --onelineShows a condensed, one-line view of the commit history.
git show [commit]Shows the changes for a specific commit.
git diffShows changes in the working directory that are not yet staged.
git diff --stagedShows 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:

CommandShows
git log --oneline --graph --allVisual branch graph
git log -n 5Last 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:

TypeWhen to use
Lightweight (git tag name)Personal markers
Annotated (git tag -a)Releases

Quick Reference

Daily Commands

TaskCommand
Check statusgit status
Stage allgit add .
Stage onegit add file
Commitgit commit -m "msg"
Pushgit push
Pullgit pull

Branching

TaskCommand
List branchesgit branch
Create branchgit branch name
Switchgit switch name
Create + switchgit switch -c name
Mergegit merge name
Deletegit branch -d name
Rebasegit rebase target

Undoing

TaskCommand
Unstage filegit reset file
Discard changesgit restore file
Undo last commit (keep changes)git reset --soft HEAD~1
Undo last commit (discard)git reset --hard HEAD~1
Revert a commitgit revert commit
Amend last commitgit commit --amend
Interactive rebasegit rebase -i HEAD~N

Remotes

TaskCommand
List remotesgit remote -v
Add remotegit remote add name url
Remove remotegit remote rm name
Fetchgit fetch origin
Pull with rebasegit pull --rebase

Inspection

TaskCommand
Full loggit log
One-line loggit log --oneline
Visual graphgit log --oneline --graph --all
Show a commitgit show commit
Unstaged diffgit diff
Staged diffgit diff --staged

Tags

TaskCommand
Lightweight taggit tag name
Annotated taggit tag -a name -m "msg"
List tagsgit tag
Push tagsgit push origin --tags
Delete localgit tag -d name
Delete remotegit push origin --delete name

Best Practices (Quick Reminder)

✅ Do:

  • git status before every commit
  • git pull --rebase to keep history clean
  • Commit small, focused changes
  • Use branches for everything
  • Read git diff --staged before committing
  • Push often — local work isn’t backup

❌ Don’t:

  • Commit secrets
  • Rewrite pushed history
  • Force-push shared branches
  • Commit without a message
  • Use --hard casually
  • Rebase public branches

Summary

GroupPurpose
BasicDaily commands
BranchingIsolate and merge work
UndoingRecover from mistakes
RemotesCollaborate
InspectionRead history
TagsMark 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 --staged shows what’s about to be committed
  • Tags mark releases — annotated for public, lightweight for personal
  • git log --oneline --graph --all shows 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.

Was this helpful?


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!