@@ -212,6 +212,13 @@ def create_pr_or_update_branch_on_api_repo(
212212 print (f"Switching to branch: { branch_name } " )
213213 api_repo .git .checkout ('-B' , branch_name )
214214
215+ # Pull remote branch contents if it exists so we commit on top
216+ try :
217+ api_repo .git .pull ('origin' , branch_name )
218+ print (f"Pulled latest from origin/{ branch_name } " )
219+ except GitCommandError :
220+ print (f"No existing remote branch '{ branch_name } ' to pull." )
221+
215222 # Create repo directory if it doesn't exist
216223 repo_dir = os .path .join (temp_dir , repo_name )
217224 os .makedirs (repo_dir , exist_ok = True )
@@ -250,11 +257,8 @@ def create_pr_or_update_branch_on_api_repo(
250257 print ("Adding remote 'origin' with access token" )
251258 origin = api_repo .create_remote ("origin" , auth_url )
252259
253- # Force Push because we allow APIs for a specific version to
254- # reflect the latest representation of the version/ref.
255260 print (f"Pushing branch to remote..." )
256- api_repo .git .push ('--force' , '--set-upstream' ,
257- 'origin' , branch_name )
261+ api_repo .git .push ('--set-upstream' , 'origin' , branch_name )
258262
259263 # Check if PR already exists
260264 existing_pr = check_existing_pr (
0 commit comments