Git Commands Cheat Sheet — Complete Reference & Workflow Guide

High-frequency Git commands with clear explanations for daily developer workflows, branching, rebasing, and emergency undo operations.

Getting Started & Repository Setup

git init

Initialize a brand new local Git repository in current directory

git clone <url>

Clone a remote repository to your local machine

git status

Show current branch, staged, unstaged, and untracked files

git log --oneline -n 10

View the last 10 commits in a clean single-line format

Staging & Committing Changes

git add .

Stage all modified and newly created files in current directory

git add -p <file>

Interactively review and stage individual code hunks

git commit -m "feat: <message>"

Commit staged changes with a concise message

git commit --amend --no-edit

Add staged changes to the previous commit without changing the commit message

Branching & Merging

git branch -a

List all local and remote branches

git checkout -b <branch-name>

Create and switch to a new branch (or: git switch -c <name>)

git merge <branch>

Merge the specified branch into your current branch

git branch -d <branch-name>

Delete a local branch that has been safely merged

Stashing & Temporary Storage

git stash

Save modified tracked files to a temporary stash stack

git stash pop

Restore and remove the most recently stashed changes

git stash list

List all stashed work items with stash indices

Undoing Mistakes & Time Travel

git restore <file>

Discard unstaged changes in a file and revert to HEAD

git restore --staged <file>

Unstage a file while keeping your local modifications intact

git reset --soft HEAD~1

Undo the last commit, keeping all changed files staged

git revert <commit-hash>

Create a new commit that safely inverts changes from an earlier commit