Table of Contents
- Setup and Configuration
- Starting a Repository
- Staging and Committing
- Viewing History
- Branching
- Merging and Rebasing
- Remote Repositories
- Stashing
- Undoing Changes
- Tags
- Advanced: Useful One-Liners
- Git Aliases Worth Setting Up
- The 10 Commands You’ll Use Every Day
- Related Articles
- Which Git Commands Should You Memorize First?
- Common Questions
Git is the foundation of modern software development. Whether you work alone or on a team of hundreds, knowing the right commands saves hours every week. This Git commands cheat sheet covers the 30 most essential commands, organized by workflow stage, with practical examples you can copy directly into your terminal.

Key takeaways
- Follow the main steps in Git Commands Cheat Sheet 2026: 30 Essential Commands in order; skipping prerequisites is the most common source of errors.
- Prioritize official packages, backups, and rollback paths when the guide touches servers, security, or production tools.
- Use the Next Read links at the end to continue with related setup, performance, or protection tasks.
Setup and Configuration
Before using Git, configure your identity. These settings are stored globally and attached to every commit you make.
# Set your name and email
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
# Set default branch name to main
git config --global init.defaultBranch main
# Set VS Code as your default editor
git config --global core.editor "code --wait"
# View all config settings
git config --list
Starting a Repository

# Initialize a new repo in the current folder
git init
# Clone an existing remote repo
git clone https://github.com/user/repo.git
# Clone into a specific folder name
git clone https://github.com/user/repo.git my-folder
Staging and Committing
The staging area lets you build commits selectively — only include the changes you intend to ship.
# Check what's changed
git status
# Stage a specific file
git add filename.js
# Stage all changes in current directory
git add .
# Stage parts of a file interactively
git add -p filename.js
# Commit staged changes
git commit -m "Your commit message"
# Stage and commit tracked files in one step
git commit -am "Your commit message"
Viewing History
# View commit log
git log
# Compact one-line log
git log --oneline
# Log with branch graph
git log --oneline --graph --all
# Show changes in a specific commit
git show abc1234
# Show who changed each line in a file
git blame filename.js
Branching
Branches are cheap and fast in Git. Use them for every feature, bug fix, and experiment.
# List all local branches
git branch
# Create a new branch
git branch feature/login
# Switch to a branch
git checkout feature/login
# Create and switch in one command (modern syntax)
git switch -c feature/login
# Delete a branch (safe — won't delete unmerged)
git branch -d feature/login
# Force delete a branch
git branch -D feature/login
Merging and Rebasing
# Merge a branch into the current branch
git merge feature/login
# Merge without a fast-forward (preserves branch history)
git merge --no-ff feature/login
# Rebase current branch onto main
git rebase main
# Interactive rebase to clean up last 3 commits
git rebase -i HEAD~3
# Abort a rebase in progress
git rebase --abort
Remote Repositories
# Show remotes
git remote -v
# Add a remote
git remote add origin https://github.com/user/repo.git
# Fetch changes without merging
git fetch origin
# Pull (fetch + merge)
git pull origin main
# Push to remote
git push origin main
# Push and set upstream tracking
git push -u origin feature/login
Stashing
Stash saves your uncommitted work so you can switch branches without committing half-done changes.
# Stash current changes
git stash
# Stash with a descriptive message
git stash push -m "WIP: login form validation"
# List all stashes
git stash list
# Apply most recent stash (keeps it in list)
git stash apply
# Apply and remove from list
git stash pop
# Drop a specific stash
git stash drop stash@{2}
Undoing Changes
# Discard unstaged changes in a file
git checkout -- filename.js
# Unstage a file (keep changes)
git restore --staged filename.js
# Undo last commit (keep changes staged)
git reset --soft HEAD~1
# Undo last commit (keep changes unstaged)
git reset HEAD~1
# Undo last commit and discard all changes (DESTRUCTIVE)
git reset --hard HEAD~1
# Create a new commit that reverses a previous commit
git revert abc1234
Tags
# Create a lightweight tag
git tag v1.0.0
# Create an annotated tag
git tag -a v1.0.0 -m "Version 1.0 release"
# Push tags to remote
git push origin --tags
# Delete a tag locally and remotely
git tag -d v1.0.0
git push origin --delete v1.0.0
Advanced: Useful One-Liners
# Find which commit introduced a bug (binary search)
git bisect start
git bisect bad HEAD
git bisect good v1.2.0
# Apply a specific commit from another branch
git cherry-pick abc1234
# Clean untracked files and directories
git clean -fd
# Show all files changed in last commit
git diff HEAD~1 --name-only
Git Aliases Worth Setting Up
Add these to your ~/.gitconfig to save keystrokes on the commands you use most:
[alias]
st = status
co = checkout
br = branch
lg = log --oneline --graph --all
unstage = restore --staged
The 10 Commands You’ll Use Every Day
Out of 30 commands, these 10 cover 90% of daily Git work: git status, git add, git commit, git pull, git push, git branch, git checkout (or switch), git merge, git log --oneline, and git stash. Master these first, then layer in the rest as needed.
Related Articles
- Best CI/CD Tools 2026: GitHub Actions, Jenkins, or GitLab? — Pair your Git skills with the right CI/CD pipeline for your team.
- Docker Kanvas: Compose Files to Kubernetes Without YAML — Take your dev workflow further with containerized deployments.
Which Git Commands Should You Memorize First?
You do not need all 30 commands in muscle memory on day one. The most useful starting set is the group you touch every time you work: status, add, commit, pull, push, branch, and log. Once those feel natural, the rest of Git becomes much easier to reason about.
For people building a fuller developer workflow, this cheat sheet pairs well with GitHub Actions for Beginners and the broader Dev / IT Ops complete guide. Git matters most when it connects cleanly to testing, CI/CD, and team collaboration.
| Command group | Learn first? | Why |
|---|---|---|
| Status, add, commit | Yes | The core daily loop for saving meaningful work. |
| Pull, push, branch | Yes | Essential once you collaborate or work across features. |
| Reset, rebase, cherry-pick | Later | Powerful, but easier to misuse before you know the basics. |








