Git Commands Cheat Sheet 2026 — Every Command You Need

Bookmark this page. Use Ctrl+F (or Cmd+F on Mac) to find what you need. This cheat sheet covers Git commands from basics to advanced workflows. Last updated: April 2026 Setup and Config Command Description git config --global user.name "Alex" Set your name (shown in commits) git config --global user.email "alex@example.com" Set your email git config --global init.defaultBranch main Set default branch name git config --list Show all config settings git init Create a new repository git clone <url> Clone a remote repository git clone <url> <folder> Clone into a specific folder Basic Workflow Command Description git status Show changed, staged, and untracked files git add <file> Stage a file for commit git add . Stage all changes git add -p Stage changes interactively (hunk by hunk) git commit -m "message" Commit staged changes git commit -am "message" Stage tracked files and commit (does NOT stage untracked files) git commit --amend Modify the last commit (add files or fix message) git diff Show unstaged changes git diff --staged Show staged changes (ready to commit) git diff HEAD Show all changes (staged + unstaged) Working Directory → git add → Staging Area → git commit → Repository Viewing History Command Description git log Show commit history git log --oneline One line per commit git log --oneline --graph --all Visual branch graph git log -5 Show last 5 commits git log --author="Alex" Filter by author git log --since="2026-01-01" Commits after a date git log -- <file> History of a specific file git show <commit> Show details of a commit git blame <file> Show who changed each line Branching Command Description git branch List local branches git branch -a List all branches (local + remote) git branch <name> Create a new branch git branch -d <name> Delete a branch (safe — won’t delete unmerged) git branch -D <name> Force delete a branch git branch -m <old> <new> Rename a branch git switch <name> Switch to a branch git switch -c <name> Create and switch to a new branch git checkout <name> Switch to a branch (older syntax) git checkout -b <name> Create and switch (older syntax) Branch Workflow (ASCII Diagram) main: A --- B --- C --- F (merge commit) \ / feature: D --- E - Merging Command Description git merge <branch> Merge branch into current branch git merge --no-ff <branch> Force a merge commit (no fast-forward) git merge --squash <branch> Merge all commits as one (does not auto-commit) git merge --abort Cancel a merge in progress Resolving Conflicts When Git cannot auto-merge, it marks conflicts in the file: ...

March 17, 2026 · 6 min