Git Workflow
Daily git commands, rebase vs merge, undo recipes, conventional commits.
gitdevops
# Git Workflow ## Daily commands ```bash git status git diff # unstaged git diff --staged # staged git add -p # interactive staging git commit -m "feat: ..." git push -u origin feature/x git pull --rebase ``` ## Branching - `git switch -c feature/login` - `git switch main` then `git merge feature/login` (merge commit) - Or rebase: on feature -> `git rebase main`, then fast-forward merge ## Rebase vs merge - Merge preserves history (use for shared/long-lived branches). - Rebase makes linear history (use for personal feature branches before PR). - Never rebase commits that have been pushed and others may have based work on. ## Undo recipes - Discard local change: `git restore <file>` - Unstage: `git restore --staged <file>` - Amend last commit: `git commit --amend` - Undo last commit, keep changes: `git reset --soft HEAD~1` - Undo last commit, discard changes: `git reset --hard HEAD~1` - Recover deleted commit: `git reflog` then `git reset --hard <sha>` ## Conventional commits `<type>(<scope>): <subject>` Types: feat, fix, docs, style, refactor, perf, test, build, ci, chore. Example: `fix(auth): handle expired refresh token` ## Stash `git stash push -m "wip"` / `git stash pop` / `git stash list`
API: /api/skills/git-workflow