# Git Quick Reference

## Setup
| Command | Purpose |
|---|---|
| `git init` | Create new repo |
| `git clone <url>` | Clone existing repo |
| `git config --global user.name "Name"` | Set name |
| `git config --global user.email "email"` | Set email |

## Daily Workflow
| Command | Purpose |
|---|---|
| `git status` | See what's changed |
| `git add <file>` | Stage specific file |
| `git add .` | Stage everything |
| `git commit -m "msg"` | Commit staged changes |
| `git diff` | See unstaged changes |
| `git diff --staged` | See staged changes |
| `git log --oneline` | Compact history |

## Branching
| Command | Purpose |
|---|---|
| `git branch` | List branches |
| `git branch <name>` | Create branch |
| `git checkout <name>` | Switch branch |
| `git checkout -b <name>` | Create + switch |
| `git merge <branch>` | Merge into current |
| `git branch -d <name>` | Delete branch |

## Remote
| Command | Purpose |
|---|---|
| `git remote -v` | List remotes |
| `git push origin <branch>` | Push branch |
| `git pull origin <branch>` | Fetch + merge |
| `git fetch` | Download only |

## Undo
| Scenario | Command |
|---|---|
| Discard working changes | `git checkout -- <file>` |
| Unstage a file | `git reset HEAD <file>` |
| Undo last commit (keep changes) | `git reset --soft HEAD~1` |
| Undo a pushed commit | `git revert <sha>` |
| Discard everything | `git reset --hard HEAD` |

## Stash
| Command | Purpose |
|---|---|
| `git stash` | Save dirty state |
| `git stash pop` | Restore + delete stash |
| `git stash list` | Show all stashes |
| `git stash drop` | Delete top stash |

## Decision Tree: "How Do I Undo?"

```
Did you commit it?
├── No → Is it staged?
│   ├── Yes → git reset HEAD <file>
│   └── No → git checkout -- <file>
└── Yes → Did you push it?
    ├── No → git reset --soft HEAD~1
    └── Yes → git revert <sha>
```
