Last updated: April 12, 2026
Git Commands Cheatsheet
Quick Answer
This cheatsheet covers the 40 most essential Git commands grouped by workflow: setup, staging, branching, merging, remote operations, inspection, and undo. Bookmark it for quick reference during development.
Setup
| Command | Description |
|---|---|
| git init | Initialize a new Git repository in the current directory git init |
| git clone <url> | Clone a remote repository to your local machine git clone https://github.com/user/repo.git |
| git config --global user.name "<name>" | Set your global Git username git config --global user.name "John Doe" |
| git config --global user.email "<email>" | Set your global Git email git config --global user.email "john@example.com" |
Staging
| Command | Description |
|---|---|
| git status | Show the working tree status (modified, staged, untracked files) |
| git add <file> | Stage a specific file for commit git add index.ts |
| git add . | Stage all changes in the current directory and subdirectories |
| git add -p | Interactively stage hunks of changes |
| git reset <file> | Unstage a file while keeping its changes git reset index.ts |
Committing
| Command | Description |
|---|---|
| git commit -m "<message>" | Commit staged changes with a message git commit -m "feat: add login page" |
| git commit --amend | Modify the most recent commit (message or content) |
| git commit --amend --no-edit | Add staged changes to the last commit without changing the message |
Branching
| Command | Description |
|---|---|
| git branch | List all local branches |
| git branch <name> | Create a new branch git branch feature/login |
| git branch -d <name> | Delete a branch (safe — only if merged) git branch -d feature/login |
| git branch -D <name> | Force delete a branch (even if not merged) |
| git checkout <branch> | Switch to an existing branch git checkout main |
| git checkout -b <name> | Create and switch to a new branch git checkout -b feature/auth |
| git switch <branch> | Switch branches (modern alternative to checkout) git switch main |
Merging
| Command | Description |
|---|---|
| git merge <branch> | Merge a branch into the current branch git merge feature/login |
| git merge --no-ff <branch> | Merge with a merge commit even if fast-forward is possible |
| git rebase <branch> | Rebase current branch onto another branch git rebase main |
| git rebase --abort | Abort an in-progress rebase and return to the original state |
| git cherry-pick <commit> | Apply a specific commit to the current branch git cherry-pick a1b2c3d |
Stashing
| Command | Description |
|---|---|
| git stash | Temporarily save uncommitted changes |
| git stash pop | Restore the most recent stash and remove it from the stash list |
| git stash list | List all stashed changes |
| git stash drop | Delete the most recent stash |
Remote
| Command | Description |
|---|---|
| git push | Push committed changes to the remote |
| git push -u origin <branch> | Push and set upstream tracking for a new branch git push -u origin feature/auth |
| git pull | Fetch and merge changes from the remote |
| git fetch | Download remote changes without merging |
| git remote -v | Show remote repository URLs |
Inspection
| Command | Description |
|---|---|
| git log --oneline | Show commit history in compact format |
| git log --graph --oneline --all | Show commit graph for all branches |
| git diff | Show unstaged changes |
| git diff --staged | Show staged changes (ready to commit) |
| git show <commit> | Show details of a specific commit git show a1b2c3d |
| git bisect start | Start binary search to find a commit that introduced a bug |
Tagging
| Command | Description |
|---|---|
| git tag <name> | Create a lightweight tag at the current commit git tag v1.0.0 |
| git tag -a <name> -m "<msg>" | Create an annotated tag with a message git tag -a v1.0.0 -m "Release 1.0" |
Undo
| Command | Description |
|---|---|
| git reset --soft HEAD~1 | Undo the last commit but keep changes staged |
| git reset --hard HEAD~1 | Undo the last commit and discard changes (destructive) |
| git revert <commit> | Create a new commit that undoes a previous commit git revert a1b2c3d |
Frequently Asked Questions
More Cheatsheets
Docker Commands Cheatsheet
This cheatsheet covers 35 essential Docker commands for managing containers, images, volumes, and ne...
Linux Commands Cheatsheet
This cheatsheet covers 40 essential Linux/Unix commands for daily development: file navigation, text...
HTTP Status Codes Cheatsheet
HTTP status codes are 3-digit numbers returned by servers. 1xx = informational, 2xx = success, 3xx =...
Regex Syntax Cheatsheet
This cheatsheet covers essential regex syntax: character classes, quantifiers, anchors, groups, and ...