DevOpsil
Git26 commands

Git Cheat Sheet

Essential Git commands for version control — branching, merging, rebasing, stashing, and collaboration.

Setup & Config

CommandDescription
git init
Initialize a new repo
git clone <url>
Clone a repository
git config --global user.name "Name"
Set username
git config --global user.email "email"
Set email

Basic Workflow

CommandDescription
git status
Show working tree status
git add .
Stage all changes
git add <file>
Stage specific file
git commit -m "msg"
Commit staged changes
git push
Push to remote
git pull
Fetch and merge from remote
git diff
Show unstaged changes
git diff --staged
Show staged changes

Branching

CommandDescription
git branch
List branches
git branch <name>
Create branch
git checkout <branch>
Switch branch
git checkout -b <name>
Create and switch
git merge <branch>
Merge branch into current
git rebase <branch>
Rebase onto branch
git branch -d <name>
Delete merged branch

Stash & Undo

CommandDescription
git stash
Stash changes
git stash pop
Apply and remove stash
git stash list
List stashes
git reset --soft HEAD~1
Undo last commit, keep changes
git reset --hard HEAD~1
Undo last commit, discard changes
git revert <hash>
Create undo commit
git log --oneline -10
Show last 10 commits