Loading...
Loading...
Complete git workflow patterns including GitHub Flow branching, atomic commits with interactive staging, merge and rebase strategies, and recovery operations using reflog. Essential patterns for clean history. Use when managing branches, defining branching strategy, or recovering git history.
npx skill4agent add yonatangross/orchestkit git-workflow# Feature branches (link to issue)
issue/<number>-<brief-description>
issue/123-add-user-auth
# When no issue exists
feature/<description>
fix/<description>
hotfix/<description>mainmainmain[ ] Does ONE logical thing
[ ] Leaves codebase working (tests pass)
[ ] Message doesn't need "and" in title
[ ] Can be reverted independently
[ ] Title < 50 chars, body wraps at 72# Stage changes hunk-by-hunk
git add -p
# Options:
# y - stage this hunk
# n - skip this hunk
# s - split into smaller hunks
# e - manually edit the hunk
# q - quit
# Review what's staged
git diff --staged # What will be committed
git diff # What won't be committed# Separate concerns
git add -p && git commit -m "refactor: Extract database pool"
git add -p && git commit -m "feat(#456): Add query caching"
# Never combine unrelated changes
# BAD: "feat: Add auth and fix formatting"
# GOOD: Two separate commits# ALWAYS check reflog first - it has everything
git reflog
# Shows ALL recent HEAD movements
# Even "deleted" commits live here for 90 days| Scenario | Not Pushed | Already Pushed |
|---|---|---|
| Undo commit | | |
| Wrong branch | cherry-pick + reset | cherry-pick + revert |
| Lost commits | | N/A |
| Bad rebase | | reflog + force-with-lease |
# Undo last commit, keep changes staged
git reset --soft HEAD~1
# Find lost commits
git reflog | grep "your message"
# Recover to previous state
git reset --hard HEAD@{1}
# Safe force push (feature branches only)
git push --force-with-lease# 1. Start fresh
git checkout main && git pull origin main
git checkout -b issue/123-my-feature
# 2. Work with atomic commits
git add -p
git commit -m "feat(#123): Add User model"
# 3. Stay updated
git fetch origin && git rebase origin/main
# 4. Push and PR
git push -u origin issue/123-my-feature
gh pr create --fill
# 5. Cleanup after merge
git checkout main && git pull
git branch -d issue/123-my-featureAvoid:
- Long-lived branches (> 1 week)
- Merging main into feature (use rebase)
- Direct commits to main
- Force push to shared branches
- Commits that need "and" in message
- Committing broken codegit add -pork:commitgit-recoverystacked-prsork:create-pr| Decision | Choice | Rationale |
|---|---|---|
| Branching model | GitHub Flow | Simple single-branch workflow, main is always deployable |
| Merge strategy | Rebase over merge | Keeps history clean and linear, easier to bisect |
| Branch naming | issue/<number>-<desc> | Links work to tracking, enables automation |
| Commit granularity | Atomic (one thing) | Independent revert, clear history, easier review |
| Force push | --force-with-lease only | Prevents overwriting others' work on shared branches |
rules/| Category | Rule | Impact | Key Pattern |
|---|---|---|---|
| Branch Protection | | CRITICAL | Protected branches, required PR workflow |
| Merge Strategy | | HIGH | Rebase-first, conflict resolution, force-with-lease |
| History Hygiene | | HIGH | Squash WIP, fixup commits, clean history |
| Recovery | | CRITICAL | Reflog recovery for lost commits and branches |
| Recovery | | CRITICAL | Safe vs dangerous reset modes |
| Recovery | | HIGH | Stash management and dropped stash recovery |
| Stacked PRs | | HIGH | Stack planning, PR creation, dependency tracking |
| Stacked PRs | | HIGH | Rebase management, force-with-lease, retargeting |
| Monorepo | | MEDIUM | --add-dir, per-service CLAUDE.md, workspace detection |