Sponsored
Ad slot is loading...

Git Cheat Sheet

Complete Git command reference. Setup, basic commands, branching, remote operations, undo changes, stash, diff, and tagging. Quick reference for version control workflows.

Git Commands (37)

Setup
git init
Initialize new repository
Setup
git clone <url>
Clone remote repository
Setup
git config --global user.name "name"
Set username
Setup
git config --global user.email "email"
Set email
Basic
git status
Show working tree status
Basic
git add <file>
Add file to staging
Basic
git add .
Add all files to staging
Basic
git commit -m "message"
Commit staged changes
Basic
git log
Show commit history
Basic
git log --oneline
Compact commit history
Branch
git branch
List all branches
Branch
git branch <name>
Create new branch
Branch
git checkout <branch>
Switch to branch
Branch
git checkout -b <name>
Create and switch branch
Branch
git merge <branch>
Merge branch into current
Branch
git branch -d <name>
Delete branch
Remote
git remote -v
Show remote repositories
Remote
git remote add <name> <url>
Add remote repository
Remote
git fetch <remote>
Fetch from remote
Remote
git pull <remote> <branch>
Pull and merge remote
Remote
git push <remote> <branch>
Push to remote
Remote
git push -u origin main
Push and set upstream
Undo
git reset <file>
Unstage file
Undo
git reset HEAD~1
Undo last commit, keep changes
Undo
git reset --hard HEAD~1
Undo last commit, discard changes
Undo
git revert <commit>
Revert commit safely
Undo
git stash
Stash working changes
Undo
git stash pop
Apply stashed changes
Stash
git stash list
List all stashes
Stash
git stash clear
Clear all stashes
Diff
git diff
Show unstaged changes
Diff
git diff --staged
Show staged changes
Diff
git diff <branch>
Compare with branch
Tag
git tag
List all tags
Tag
git tag <name>
Create tag
Tag
git tag -a <name> -m "msg"
Create annotated tag
Tag
git push --tags
Push tags to remote

Common Workflows

New Feature
git checkout -b feature
git add .
git commit -m "msg"
git push -u origin feature
Merge Branch
git checkout main
git merge feature
git push
git branch -d feature
Undo Commit
git log --oneline
git reset HEAD~1
git status
git add . / git checkout .

Git Best Practices

Commit often: Small changes
Write messages: Descriptive
Branch for features: Isolate work
Pull before push: Stay synced
Use .gitignore: Exclude files
Review diff: Before commit
Tag releases: Mark versions
Stash changes: Save work
Sponsored
Ad slot is loading...