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:
- Daily Commands — The 6 you use every day
- Branching — Work on features safely
- Undoing Things — Fix mistakes
- Commit Messages — Write good ones
Tip: Cmd/Ctrl+F to find specific commands.
Daily Commands
| Command | What it does |
|---|---|
git status | See what’s changed |
git add . | Stage all changes |
git add -p | Stage changes interactively |
git commit -m "message" | Commit with message |
git push | Push to remote |
git pull | Pull from remote |
Branching
| Command | What it does |
|---|---|
git branch | List branches |
git branch feature-name | Create branch |
git checkout feature-name | Switch to branch |
git checkout -b feature-name | Create and switch |
git merge feature-name | Merge branch into current |
git branch -d feature-name | Delete branch |
Viewing History
| Command | What it does |
|---|---|
git log --oneline | Compact history |
git log --oneline -10 | Last 10 commits |
git log --graph | Visual branch graph |
git diff | See unstaged changes |
git diff --staged | See staged changes |
git show HEAD | Show last commit |
Undoing Things
Oops, I need to undo…
| Situation | Command |
|---|---|
| Unstage a file | git reset HEAD file.txt |
| Discard changes to file | git 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 commit | git revert <commit-hash> |
| Amend last commit message | git commit --amend -m "new message" |
| Add to last commit | git add . && git commit --amend --no-edit |
Stashing
| Command | What it does |
|---|---|
git stash | Save changes for later |
git stash pop | Restore stashed changes |
git stash list | See all stashes |
git stash drop | Delete top stash |
git stash clear | Delete all stashes |
Remote Operations
| Command | What it does |
|---|---|
git remote -v | Show remotes |
git fetch | Download changes (don’t merge) |
git pull --rebase | Pull and rebase |
git push -u origin branch | Push new branch |
git push --force-with-lease | Safe force push |
Commit Message Formula
<type>: <short description>
<optional body>
<optional footer>
Types
| Type | Use for |
|---|---|
feat | New feature |
fix | Bug fix |
refactor | Code refactoring |
docs | Documentation |
style | Formatting |
test | Tests |
chore | Maintenance |
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 -pto 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-leaseinstead of--forceto 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.
Related
- Project Setup — Start projects right
- Shipping Fast — Deploy with confidence
- Mistakes to Avoid — Learn from others
✓ Copied to clipboard!