>_toolkitbox

~/tools / Git Cheatsheet

Git Cheatsheet

A searchable quick reference for common git commands.

For those "what was that command again" moments — search by the command itself or by what you're trying to do (e.g. "undo", "stash"). Covers everything from the basics to branching and history rewrites.

# Use Cases

  • You know what you want to do (undo the last commit) but can't recall the exact command
  • Stashing your work-in-progress changes so you can switch branches
  • Recalling the command to view only staged changes before a review

# Usage

  1. Type a command name (e.g. branch) or what you're trying to do (e.g. undo, stash) into the search box.
  2. Results are filtered by matching either the command or its description.
  3. Leave it blank to see the full list.
  • git initCreate a new Git repository
  • git clone <url>Clone a remote repository
  • git statusShow the working tree status
  • git add .Stage all changes
  • git commit -m "message"Commit staged changes
  • git commit --amendAmend the previous commit
  • git push origin <branch>Push a branch to the remote
  • git pullFetch and merge changes from the remote
  • git fetchFetch remote changes without merging
  • git branchList branches
  • git branch <name>Create a new branch
  • git checkout -b <name>Create and switch to a new branch
  • git switch <branch>Switch to a branch
  • git merge <branch>Merge a branch into the current one
  • git rebase <branch>Replay current changes on top of another branch
  • git log --onelineShow commit history, one line per commit
  • git diffShow unstaged changes in the working directory
  • git diff --stagedShow staged changes
  • git stashTemporarily shelve uncommitted changes
  • git stash popRestore the most recently stashed changes
  • git reset --soft HEAD~1Undo the last commit, keeping the changes
  • git reset --hard HEAD~1Undo the last commit and discard the changes
  • git revert <commit>Create a new commit that undoes a given commit
  • git tag <name>Tag the current commit
  • git remote -vList configured remotes
  • git cherry-pick <commit>Apply a single commit onto the current branch

# FAQ

Is it safe to run these commands as-is?
Some, especially git reset --hard and git push --force variants, can permanently lose changes or commit history. Understand what a command does before running it.

# Related

# Learn more on our sister sites

  • Learn Git

    Try the commands in a simulated terminalprodou.net