@@ -314,18 +314,26 @@ export class Git {
314314 // Remove local changes so that no conflict can happen
315315 debug ( 'Removing local changes.' )
316316 await this . git . reset ( ResetMode . HARD )
317- debug ( `Go to ${ this . branch } branch` )
318- await this . git . checkout ( this . branch )
319- debug ( 'Removing local changes.' )
320- await this . git . reset ( ResetMode . HARD )
321- debug ( 'Cleaning local values and directories.' )
322- await this . git . clean ( CleanOptions . FORCE , [ '-d' ] )
323- debug ( 'Get the latest branch from:' , this . remote )
324- await this . git . fetch ( this . remote , this . branch )
325- debug ( 'Reconciling divergent branches.' )
326- await this . git . merge ( [ `${ this . remote } /${ this . branch } ` , '--strategy-option=theirs' ] )
327- debug ( 'Trying to remove upstream commits: ' , this . remote )
328- await this . git . push ( [ this . remote , this . branch , '--force' ] )
317+ if ( this . isRootClone ( ) ) {
318+ debug ( `Go to ${ this . branch } branch` )
319+ await this . git . checkout ( this . branch )
320+ debug ( 'Removing local changes.' )
321+ await this . git . reset ( ResetMode . HARD )
322+ debug ( 'Cleaning local values and directories.' )
323+ await this . git . clean ( CleanOptions . FORCE , [ '-d' ] )
324+ debug ( 'Get the latest branch from:' , this . remote )
325+ await this . git . fetch ( this . remote , this . branch )
326+ debug ( 'Reconciling divergent branches.' )
327+ await this . git . merge ( [ `${ this . remote } /${ this . branch } ` , '--strategy-option=theirs' ] )
328+ debug ( 'Trying to remove upstream commits: ' , this . remote )
329+ await this . git . push ( [ this . remote , this . branch , '--force' ] )
330+ } else {
331+ // Worktree recovery: rebase session branch on top of remote; our changes win conflicts
332+ debug ( 'Get the latest branch from:' , this . remote )
333+ await this . git . fetch ( this . remote , this . branch )
334+ debug ( 'Rebasing session branch on top of remote.' )
335+ await this . git . raw ( [ 'rebase' , `${ this . remote } /${ this . branch } ` , '--strategy-option=ours' ] )
336+ }
329337 } catch ( error ) {
330338 const errorMessage = getSanitizedErrorMessage ( error )
331339 debug ( 'Failed to remove upstream commits: ' , errorMessage )
0 commit comments