|
| 1 | +# Strategy for Handling Incomplete Remote Branches |
| 2 | + |
| 3 | +## Overview |
| 4 | +When returning to a project with incomplete work in remote branches, a systematic approach helps assess and decide how to proceed with each branch. |
| 5 | + |
| 6 | +## Discovery Commands |
| 7 | +```bash |
| 8 | +# List all branches |
| 9 | +git branch -a |
| 10 | + |
| 11 | +# Find unmerged branches |
| 12 | +git branch --no-merged main |
| 13 | + |
| 14 | +# Recent branch activity |
| 15 | +git for-each-ref --sort=-committerdate refs/remotes/origin --format='%(committerdate:short) %(refname:short) %(subject)' |
| 16 | + |
| 17 | +# Check specific branch differences |
| 18 | +git log main..origin/branch-name --oneline |
| 19 | +git diff main...origin/branch-name --stat |
| 20 | +``` |
| 21 | + |
| 22 | +## Decision Framework |
| 23 | + |
| 24 | +### 1. Create Draft PR |
| 25 | +**When**: Work is partially complete but needs visibility |
| 26 | +```bash |
| 27 | +gh pr create --draft --base main --head branch-name --title "WIP: Description" |
| 28 | +``` |
| 29 | +**Benefits**: |
| 30 | +- Documents intent and approach |
| 31 | +- Allows collaboration |
| 32 | +- Preserves context |
| 33 | +- Shows in PR list for tracking |
| 34 | + |
| 35 | +### 2. Local Continuation |
| 36 | +**When**: Work is experimental or very incomplete |
| 37 | +```bash |
| 38 | +git checkout branch-name |
| 39 | +git pull origin branch-name |
| 40 | +# Option A: Continue directly |
| 41 | +# Option B: Stash current state first |
| 42 | +git stash push -m "Previous WIP attempt" |
| 43 | +``` |
| 44 | + |
| 45 | +### 3. Rebase and Cleanup |
| 46 | +**When**: Commits need reorganization before review |
| 47 | +```bash |
| 48 | +git checkout branch-name |
| 49 | +git rebase -i main |
| 50 | +# Clean up commit history |
| 51 | +``` |
| 52 | + |
| 53 | +### 4. Extract Useful Parts |
| 54 | +**When**: Some ideas are good but implementation needs restart |
| 55 | +```bash |
| 56 | +# Cherry-pick specific commits |
| 57 | +git cherry-pick commit-hash |
| 58 | + |
| 59 | +# Or create patches |
| 60 | +git format-patch main..branch-name |
| 61 | +``` |
| 62 | + |
| 63 | +## Best Practices |
| 64 | + |
| 65 | +1. **Use Git Worktrees** for isolated testing: |
| 66 | + ```bash |
| 67 | + git worktree add ../project-wip branch-name |
| 68 | + ``` |
| 69 | + |
| 70 | +2. **Document Intent**: |
| 71 | + - Check commit messages for TODOs |
| 72 | + - Look for related issues |
| 73 | + - Add comments to draft PRs |
| 74 | + |
| 75 | +3. **Test Before Deciding**: |
| 76 | + ```bash |
| 77 | + poetry install |
| 78 | + poetry run pytest |
| 79 | + poetry run flake8 |
| 80 | + ``` |
| 81 | + |
| 82 | +4. **Communicate Status**: |
| 83 | + - Update PR descriptions |
| 84 | + - Close stale branches |
| 85 | + - Document decisions |
| 86 | + |
| 87 | +## Handling "WIP and Broken" Commits |
| 88 | + |
| 89 | +1. First understand what's broken: |
| 90 | + - Run tests to see failures |
| 91 | + - Check linting errors |
| 92 | + - Try running the application |
| 93 | + |
| 94 | +2. Decide on approach: |
| 95 | + - Fix and continue if close to working |
| 96 | + - Extract concepts if fundamentally flawed |
| 97 | + - Archive with explanation if obsolete |
| 98 | + |
| 99 | +3. Clean up before merging: |
| 100 | + - Squash WIP commits |
| 101 | + - Write proper commit messages |
| 102 | + - Ensure all tests pass |
| 103 | + |
| 104 | +## Branch Lifecycle Management |
| 105 | + |
| 106 | +- **Active**: Currently being developed |
| 107 | +- **Draft PR**: Under review/discussion |
| 108 | +- **Stale**: No activity >30 days |
| 109 | +- **Archived**: Kept for reference but not active |
| 110 | + |
| 111 | +Regular cleanup prevents accumulation of dead branches while preserving useful experimental work. |
0 commit comments