Home / Dev / IT Ops / Git Commands Cheat Sheet 2026: 30 Essential Commands

Git Commands Cheat Sheet 2026: 30 Essential Commands

Git Commands Cheat Sheet 2026: 30 Essential Commands | Photo by Praveen Thirumurugan on Unsplash
Table of Contents
  1. Setup and Configuration
  2. Starting a Repository
  3. Staging and Committing
  4. Viewing History
  5. Branching
  6. Merging and Rebasing
  7. Remote Repositories
  8. Stashing
  9. Undoing Changes
  10. Tags
  11. Advanced: Useful One-Liners
  12. Git Aliases Worth Setting Up
  13. The 10 Commands You’ll Use Every Day
  14. Related Articles
  15. Which Git Commands Should You Memorize First?
  16. 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.

A close-up of a laptop displaying code in a dimly lit room with a coffee mug nearby. — Photo by Daniil Komov on Pexels

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

Close-up of a person coding on a laptop, showcasing web development and programming concepts. — Photo by Lukas Blazek on Pexels
# 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.

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 groupLearn first?Why
Status, add, commitYesThe core daily loop for saving meaningful work.
Pull, push, branchYesEssential once you collaborate or work across features.
Reset, rebase, cherry-pickLaterPowerful, but easier to misuse before you know the basics.

About the author: TouchEVA is a tech journalist covering AI, software, and cybersecurity for Hubkub.com — independent tech media since 2025.

Common Questions

What is the most common Git command?

git status — you will run it constantly to see what files have changed, what is staged, and what branch you are on. It is a safe read-only command, so use it often.

What is the difference between git pull and git fetch?

git fetch downloads remote changes but does not merge them; git pull fetches and then merges in one step. Use fetch when you want to review changes before integrating.

How do I undo my last commit without losing changes?

git reset –soft HEAD~1 — this removes the commit but keeps your changes staged, so you can edit and recommit. Use –hard only when you want to discard changes entirely.

What is the right way to resolve a merge conflict?

Open the conflicted files, look for the <<<<<<<, =======, >>>>>>> markers, manually edit the content to the desired result, then git add the file and continue the merge.

Should I rebase or merge?

Merge for shared branches (preserves history), rebase for your local feature branch before pushing (keeps history linear). Never rebase commits that have already been pushed and shared.

Last Updated: April 13, 2026

TouchEVA

TouchEVA

Founder and lead writer at Hubkub. Covers software, AI tools, cybersecurity, and practical Windows/Linux workflows.

Tagged: