All Shortcuts

Git Shortcuts & Commands — Complete Cheat Sheet (24)

Complete Git commands cheat sheet covering basic operations, branching, merging, history, and advanced workflows. Essential reference for every developer using version control.

Related Shortcut Pages

Docker npm / yarn AWS CLI PowerShell tmux GNU Screen

Search all Git shortcuts interactively

Interactive Shortcut Finder

All Git Shortcuts

Basic Commands

ShortcutActionDescription
git initInitialize repoInitialize a new Git repository.
git clone [URL]Clone repoClone a remote repository locally.
git statusCheck statusShow the status of changed files.
git add .Stage allStage all changed files.
git add [file]Stage fileStage a specific file.
git commit -m [msg]CommitCommit staged changes with a message.
git pushPushPush local commits to the remote repo.
git pullPullFetch and merge remote changes.
git fetchFetchFetch remote changes without merging.

Branches

ShortcutActionDescription
git branchList branchesList local branches.
git branch [name]Create branchCreate a new branch.
git checkout [branch]Switch branchSwitch to another branch.
git checkout -b [name]Create & switchCreate and switch to a new branch.
git merge [branch]MergeMerge another branch into current.
git branch -d [name]Delete branchDelete a local branch.
git rebase [branch]RebaseRebase current branch onto another.

History & Undo

ShortcutActionDescription
git logCommit historyShow commit history.
git log --onelineOne-line logShow commits in one-line format.
git diffShow diffShow unstaged changes.
git reset HEAD [file]UnstageUnstage a staged file.
git reset --hard HEAD~1Undo last commitCompletely undo the last commit.
git stashStash changesTemporarily save current changes.
git stash popApply stashRestore stashed changes.
git cherry-pick [hash]Cherry-pickApply a specific commit to current branch.
📜 Source: Git official documentation. A curated set of the git commands that cover everyday work; git-scm.com documents the full command surface. Checked 2026-08-03.

Browse shortcuts for 269 platforms

Explore All
🔧 Spotted an error or a missing shortcut? Suggest an edit on GitHub — every accepted fix goes live on this page, the API and the CLI.

The 80% loop

Daily git is five commands: statusaddcommitpullpush. The habit that prevents most accidents is running git status before and after anything else — it tells you the branch, what's staged, and what would be committed. git add . stages everything under the current directory; prefer naming files (git add file) when a change set mixes concerns, and let git log --oneline be the sanity check that history looks the way you think it does.

Branching: cheap to make, cheap to delete

git checkout -b name creates and switches in one step (newer git also offers git switch -c). Merging brings a branch's work in with history intact; git rebase replays your commits on top of another branch for a linear history — the working rule is to rebase only commits that haven't been pushed anywhere shared, because rebase rewrites them. git branch -d deletes a merged branch and refuses an unmerged one; that refusal is a feature, not an obstacle.

The undo toolbox, sorted by blast radius

Gentlest first: git stash shelves uncommitted work and stash pop restores it — ideal for “wrong branch” moments. git reset HEAD file unstages without touching the file's contents. git cherry-pick copies a single commit onto the current branch. At the destructive end, git reset --hard HEAD~1 deletes the last commit and its changes from the working tree — use it only when you truly want the work gone, and remember committed-then-reset work is recoverable via git reflog for a grace period.

Frequently asked questions

What is the difference between git fetch and git pull?

fetch downloads remote changes without touching your working branch; pull is fetch plus merge into the current branch. Fetch first when you want to inspect before integrating.

How do I undo my last git commit?

Keep the changes: git reset HEAD~1 (they return to your working tree, unstaged). Discard them entirely: git reset --hard HEAD~1 — destructive, so be sure.

When should I rebase instead of merge in git?

Rebase local, unpushed commits to keep history linear; merge anything already shared. Rewriting pushed commits forces everyone else to untangle it.

What does git stash actually store?

Uncommitted tracked changes (staged and unstaged). git stash pop restores the most recent stash and drops it; git stash apply restores but keeps it in the stash list.

How do I copy one commit to another branch?

git cherry-pick <hash> from the target branch. It creates a new commit with the same changes — the original stays where it was.

Why won't git branch -d delete my branch?

-d refuses if the branch isn't merged, protecting unmerged work. If you're certain, -D force-deletes.

🤖 Ask AI about Git shortcuts

Open your assistant with this page preloaded as the source — great for follow-up questions like "which of these work in other apps?"

ChatGPT Claude Perplexity Gemini Grok