4 workflow strategies + 40+ commands with descriptions.
Workflow Strategies
Two long-lived branches: main (production) + develop (integration). Short-lived: feature/*, release/*, hotfix/*. Best for: versioned products, scheduled releases.
main ─────────────────── v1.0
develop ──┬──┬──────────
feature ──┘ │
release ─────┘
One long-lived branch: main. Feature branches created, then merged via PR directly to main. Requires CI. Best for: SaaS, continuous deployment.
main ──────────────────
feat ──branch──PR──merge
All developers commit to main daily. Feature flags control incomplete features in production. No long-lived branches. Best for: large teams, high velocity.
main ← all commits daily
feature flags in code
Each contributor forks the upstream repo. PRs go from fork → upstream main. Best for: open-source projects where maintainers don't know all contributors.
Git Command Reference
| Category | Command | Description |
|---|---|---|
| Init & Clone | git init | Initialize new local repository |
| Init & Clone | git clone <url> | Clone remote repository |
| Init & Clone | git clone --depth 1 <url> | Shallow clone (latest commit only) |
| Stage & Commit | git status | Show working tree status |
| Stage & Commit | git add <file> | Stage specific file |
| Stage & Commit | git add -p | Stage hunks interactively |
| Stage & Commit | git commit -m 'msg' | Commit staged changes |
| Stage & Commit | git commit --amend | Amend last commit (do not amend pushed commits) |
| Branching | git branch <name> | Create branch |
| Branching | git switch <name> | Switch to branch |
| Branching | git switch -c <name> | Create + switch |
| Branching | git branch -d <name> | Delete merged branch |
| Branching | git branch -D <name> | Force-delete branch |
| Merge & Rebase | git merge <branch> | Merge branch into current (preserves history) |
| Merge & Rebase | git merge --squash <branch> | Squash all commits into one |
| Merge & Rebase | git rebase <base> | Rebase current branch onto base |
| Merge & Rebase | git rebase -i HEAD~3 | Interactive rebase: squash/edit/drop last 3 |
| Remote | git remote add origin <url> | Add remote |
| Remote | git fetch | Download remote changes (no merge) |
| Remote | git pull | Fetch + merge current branch |
| Remote | git pull --rebase | Fetch + rebase (cleaner history) |
| Remote | git push -u origin <branch> | Push and set upstream |
| Remote | git push --force-with-lease | Safe force push (checks remote) |
| Inspect | git log --oneline --graph | Compact visual branch graph |
| Inspect | git log -p <file> | Show changes to specific file |
| Inspect | git diff | Show unstaged changes |
| Inspect | git diff --staged | Show staged changes |
| Inspect | git blame <file> | Show who changed each line |
| Inspect | git show <commit> | Show commit details + diff |
| Undo | git restore <file> | Discard unstaged changes to file |
| Undo | git restore --staged <file> | Unstage file |
| Undo | git reset HEAD~1 | Undo last commit (keep changes staged) |
| Undo | git reset --hard HEAD~1 | Undo last commit (discard changes — dangerous) |
| Undo | git revert <commit> | Create new commit that undoes a commit (safe) |
| Stash | git stash | Stash uncommitted changes |
| Stash | git stash pop | Restore last stash |
| Stash | git stash list | List all stashes |
| Tags | git tag v1.0.0 | Create lightweight tag |
| Tags | git tag -a v1.0.0 -m 'msg' | Annotated tag with message |
| Tags | git push origin --tags | Push all tags |
| Submodules | git submodule add <url> | Add submodule |
| Submodules | git submodule update --init --recursive | Init + update all submodules |
Commit Message Convention
| Type | When to Use | Example |
|---|---|---|
| feat | New feature | feat: add OAuth2 login |
| fix | Bug fix | fix: handle null user in auth middleware |
| docs | Documentation only | docs: update API reference |
| style | Formatting, no logic change | style: normalize indentation |
| refactor | Neither fix nor feature | refactor: extract user service |
| test | Adding tests | test: add unit tests for cart module |
| chore | Build/tooling changes | chore: upgrade dependencies |
| perf | Performance improvement | perf: cache DB query results |
| ci | CI/CD changes | ci: add GitHub Actions workflow |