Git Cheatsheet

Complete Git command reference — setup, branching, remotes, rebasing, and undoing mistakes.

What it does

8 sections, 60+ commands

Covers setup, staging, branching, remotes, inspection, undoing, tags, and cherry-pick.

Destructive-command warnings

Blue notes flag irreversible operations like git reset --hard and git clean -fd.

Related-entry cross-links

Commands like git revert and git reset --hard are cross-referenced so you pick the right tool.

How to use Git Cheatsheet

  1. 1
    Search or browse

    Type a keyword like 'rebase' or 'stash' in the search bar, or scroll to the section you need.

  2. 2
    Read the description

    Each entry explains what the command does and includes an example where helpful.

  3. 3
    Copy and paste

    Click the copy icon to copy the command to your clipboard and paste it directly into your terminal.

  4. 4
    Check the notes

    Blue info boxes call out important warnings — like commands that rewrite history or permanently delete data.

Frequently Asked Questions

What is the difference between git merge and git rebase?

Merge preserves history and creates a merge commit joining two branch timelines. Rebase rewrites commits from your branch on top of another, producing a linear history. Use merge for shared branches and rebase for private feature branches before opening a PR.

How do I undo the last commit without losing my changes?

Use 'git reset --soft HEAD~1' to undo the commit but keep its changes staged, or 'git reset HEAD~1' to keep them unstaged. Both options preserve your files. Only use 'git reset --hard HEAD~1' if you want to discard the changes entirely.

What is the difference between git fetch and git pull?

Fetch downloads remote changes without modifying your working directory or current branch. Pull is fetch + merge (or rebase, with --rebase). Use fetch to inspect changes before merging, especially in a team environment.

How do I interactively squash commits?

Run 'git rebase -i HEAD~N' where N is the number of commits to include. In the editor, change 'pick' to 'squash' (or 's') for the commits you want to fold into the previous one. Don't use this on commits already pushed to a shared branch.

How do I stash changes and apply them later?

Run 'git stash' to save uncommitted changes and clean your working directory. Later, use 'git stash pop' to restore them. Use 'git stash list' to see all stashes and 'git stash apply stash@{n}' to apply a specific one.

Related Tools