← Cheatsheets / Tools

Git Commands for Vibecoders

Essential Git commands you'll use daily. Commit, branch, push, fix mistakes.

git version-control cli essentials

Every command you need. Bookmark this page.

Quick links:

Tip: Cmd/Ctrl+F to find specific commands.


Daily Commands

CommandWhat it does
git statusSee what’s changed
git add .Stage all changes
git add -pStage changes interactively
git commit -m "message"Commit with message
git pushPush to remote
git pullPull from remote

Branching

CommandWhat it does
git branchList branches
git branch feature-nameCreate branch
git checkout feature-nameSwitch to branch
git checkout -b feature-nameCreate and switch
git merge feature-nameMerge branch into current
git branch -d feature-nameDelete branch

Viewing History

CommandWhat it does
git log --onelineCompact history
git log --oneline -10Last 10 commits
git log --graphVisual branch graph
git diffSee unstaged changes
git diff --stagedSee staged changes
git show HEADShow last commit

Undoing Things

Oops, I need to undo…

SituationCommand
Unstage a filegit reset HEAD file.txt
Discard changes to filegit checkout -- file.txt
Undo last commit (keep changes)git reset --soft HEAD~1
Undo last commit (discard changes)git reset --hard HEAD~1
Revert a pushed commitgit revert <commit-hash>
Amend last commit messagegit commit --amend -m "new message"
Add to last commitgit add . && git commit --amend --no-edit

Stashing

CommandWhat it does
git stashSave changes for later
git stash popRestore stashed changes
git stash listSee all stashes
git stash dropDelete top stash
git stash clearDelete all stashes

Remote Operations

CommandWhat it does
git remote -vShow remotes
git fetchDownload changes (don’t merge)
git pull --rebasePull and rebase
git push -u origin branchPush new branch
git push --force-with-leaseSafe force push

Commit Message Formula

<type>: <short description>

<optional body>

<optional footer>

Types

TypeUse for
featNew feature
fixBug fix
refactorCode refactoring
docsDocumentation
styleFormatting
testTests
choreMaintenance

Examples

git commit -m "feat: add user authentication"
git commit -m "fix: resolve login redirect loop"
git commit -m "refactor: extract validation helpers"
git commit -m "docs: update API documentation"

.gitignore Essentials

# Dependencies
node_modules/
.pnpm-store/

# Build outputs
dist/
build/
.next/
.astro/

# Environment
.env
.env.local
.env*.local

# IDE
.vscode/
.idea/
*.swp

# OS
.DS_Store
Thumbs.db

# Logs
*.log
npm-debug.log*

# Testing
coverage/

Useful Aliases

Add to ~/.gitconfig:

[alias]
  co = checkout
  br = branch
  ci = commit
  st = status
  last = log -1 HEAD
  unstage = reset HEAD --
  undo = reset --soft HEAD~1
  amend = commit --amend --no-edit
  lg = log --oneline --graph --all
  wip = commit -am "WIP"

Fixing Common Mistakes

Wrong branch

# Stash changes
git stash

# Switch to correct branch
git checkout correct-branch

# Apply changes
git stash pop

Committed to wrong branch

# Undo commit (keep changes)
git reset --soft HEAD~1

# Stash changes
git stash

# Switch branch
git checkout correct-branch

# Apply and commit
git stash pop
git add .
git commit -m "your message"

Need to update from main

# Fetch latest
git fetch origin

# Rebase on main
git rebase origin/main

# Or merge main
git merge origin/main

Merge conflicts

# After conflict occurs:
# 1. Edit conflicting files
# 2. Stage resolved files
git add .

# 3. Continue
git rebase --continue
# or
git merge --continue

Pro Tips

Tip: Use git add -p to review changes before staging

Tip: Commit early, commit often — you can squash later

Tip: Write commit messages in present tense (“add feature” not “added feature”)

Tip: Use --force-with-lease instead of --force to avoid overwriting others’ work

Tip: Set up SSH keys to avoid typing passwords: ssh-keygen -t ed25519


🎯 Get Started

If you’re new to Git:

# 1. Initialize a repo
git init

# 2. Add your files
git add .

# 3. Make your first commit
git commit -m "initial commit"

# 4. Create a GitHub repo, then:
git remote add origin https://github.com/YOU/REPO.git
git push -u origin main

Now commit after every working state. Your future self will thank you.


✓ Copied to clipboard!