@@ -209,6 +209,11 @@ func (s *Service) Render(ctx context.Context, id string, progress func(msg strin
209209 if err := s .Git .BareClone (ctx , repo .URL , barePath ); err != nil {
210210 return fmt .Errorf ("cloning %s: %w" , repo .URL , err )
211211 }
212+ // Fetch after bare clone to create remote tracking refs
213+ // (bare clones don't create refs/remotes/origin/* by default).
214+ if err := s .Git .Fetch (ctx , barePath ); err != nil {
215+ return fmt .Errorf ("fetching %s: %w" , repo .URL , err )
216+ }
212217 } else {
213218 s .log ().Debug ("bare clone exists, fetching" , "url" , repo .URL , "path" , barePath )
214219 if err := s .Git .Fetch (ctx , barePath ); err != nil {
@@ -239,6 +244,12 @@ func (s *Service) Render(ctx context.Context, id string, progress func(msg strin
239244 return fmt .Errorf ("getting default branch for %s: %w" , repo .URL , err )
240245 }
241246 }
247+ // Ensure the remote tracking ref exists for the base branch so
248+ // origin/{baseBranch} resolves (especially when baseBranch differs
249+ // from the default branch, which Fetch only creates refs for).
250+ if err := s .Git .EnsureRemoteRef (ctx , barePath , baseBranch ); err != nil {
251+ return fmt .Errorf ("ensuring remote ref for %s: %w" , repo .URL , err )
252+ }
242253 // Use the remote ref to ensure we branch from the latest fetched state,
243254 // not a potentially stale local branch ref in the bare repo.
244255 startPoint := "origin/" + baseBranch
0 commit comments