User provides PR #123 which has merge conflicts between a bugfix branch and a feature branch that refactored the same code. #123 Parse PR number and fetch PR information gh pr view 123 --json title,body,headRefName,baseRefName ]]> The PR is a bugfix for a memory leak issue. This context will help prioritize preserving the fix during conflict resolution. Checkout PR branch and prepare for rebase gh pr checkout 123 --force ]]> git fetch origin main ]]> FETCH_HEAD ]]> GIT_EDITOR=true git rebase origin/main ]]> ", then run "git rebase --continue". ]]> Check for merge conflicts git status --porcelain | grep "^UU" ]]> Two files have conflicts: the main processor file and its test file. Both need to be resolved before continuing the rebase. Examine the conflicted processor file src/data/processor.ts ]]> = new Map(); 47 | 48 | <<<<<<< HEAD 49 | async processData(data: DataInput): Promise { 50 | // Refactored to use async/await 51 | const result = await this.transform(data); 52 | return result; 53 | } 54 | ======= 55 | processData(data: any[]): ProcessedData { 56 | const listener = this.createListener(); 57 | this.listeners.set(data.id, listener); 58 | 59 | return this.transform(data); 60 | } 61 | >>>>>>> abc123 (Fix memory leak in data processor) 62 | 63 | cleanup() { 64 | <<<<<<< HEAD 65 | // TODO: Implement cleanup 66 | ======= 67 | // Fix: Clear all listeners to prevent memory leak 68 | this.listeners.forEach(listener => { 69 | listener.removeAllListeners(); 70 | }); 71 | this.listeners.clear(); 72 | >>>>>>> abc123 (Fix memory leak in data processor) 73 | } 74 | } ]]> Analyze the conflicts using git blame git blame -L 49,53 HEAD -- src/data/processor.ts | cut -d' ' -f1 | sort -u | xargs -I {} git log -1 --format="%h %s" {} ]]> git log -1 --format="%h %s" abc123 ]]> HEAD (main after rebase): Has async/await refactor but missing listener logic Incoming (bugfix branch): Adds listener tracking and cleanup for memory leak fix Resolution strategy: Combine both changes - keep async/await refactor but include the listener tracking and cleanup logic. Resolve the conflicts src/data/processor.ts <<<<<<< SEARCH :start_line:48 ------- \<<<<<<< HEAD async processData(data: DataInput): Promise { // Refactored to use async/await const result = await this.transform(data); return result; } \======= processData(data: any[]): ProcessedData { const listener = this.createListener(); this.listeners.set(data.id, listener); return this.transform(data); } \>>>>>>> abc123 (Fix memory leak in data processor) ======= async processData(data: DataInput): Promise { // Create and track listener for cleanup (memory leak fix) const listener = this.createListener(); this.listeners.set(data.id, listener); // Refactored to use async/await const result = await this.transform(data); return result; } >>>>>>> REPLACE <<<<<<< SEARCH :start_line:63 ------- cleanup() { \<<<<<<< HEAD // TODO: Implement cleanup \======= // Fix: Clear all listeners to prevent memory leak this.listeners.forEach(listener => { listener.removeAllListeners(); }); this.listeners.clear(); \>>>>>>> abc123 (Fix memory leak in data processor) } ======= cleanup() { // Fix: Clear all listeners to prevent memory leak this.listeners.forEach(listener => { listener.removeAllListeners(); }); this.listeners.clear(); } >>>>>>> REPLACE ]]> Combined both changes: kept the async/await refactor from main while preserving the memory leak fix (listener tracking and cleanup) from the bugfix branch. Resolve test file conflicts src/data/processor.test.ts ]]> src/data/processor.test.ts ]]> Stage resolved files and continue rebase git add src/data/processor.ts src/data/processor.test.ts ]]> GIT_EDITOR=true git rebase --continue ]]> Final validation git status ]]> git diff origin/main --stat ]]> Successfully resolved merge conflicts for PR #123 "Fix memory leak in data processor". Resolution Summary: - src/data/processor.ts: Combined the async/await refactor with the memory leak fix by preserving listener tracking and cleanup logic within the refactored async method - src/data/processor.test.ts: Updated tests to work with the async implementation while maintaining memory leak test coverage Both the feature refactor and the critical bugfix have been preserved in the resolution. The rebase has been completed successfully and the branch is ready to be pushed. ]]> Always checkout PR with --force and rebase to reveal conflicts Fetch PR context to understand the intent of changes Use git blame and commit messages to understand the history Combine non-conflicting improvements when possible Prioritize bugfixes while accommodating refactors Use GIT_EDITOR=true to ensure non-interactive rebase operations Complete the rebase process with GIT_EDITOR=true git rebase --continue Validate that both sets of changes work together