From 58d7949ede16a7f9189a7bc45219801e507434a2 Mon Sep 17 00:00:00 2001
From: GPK <gopidesupavan@gmail.com>
Date: Sat, 9 Aug 2025 20:41:52 +0100
Subject: [PATCH] Fix redirects repository urls, use head repo when running PR
 workflows (#54301)

---
 .github/workflows/ci-amd.yml                  |  5 +++-
 .github/workflows/ci-image-checks.yml         | 10 +++++++
 ...release-management_add-back-references.svg | 26 ++++++++++++-------
 ...release-management_add-back-references.txt |  2 +-
 .../airflow_breeze/commands/ci_commands.py    |  4 +++
 .../commands/release_management_commands.py   | 26 +++++++++++++++++++
 .../release_management_commands_config.py     |  2 ++
 .../utils/add_back_references.py              | 24 ++++++++++-------
 8 files changed, 79 insertions(+), 20 deletions(-)

diff --git a/.github/workflows/ci-amd.yml b/.github/workflows/ci-amd.yml
index e738163fb458f..888df75aeb2b3 100644
--- a/.github/workflows/ci-amd.yml
+++ b/.github/workflows/ci-amd.yml
@@ -124,7 +124,8 @@ jobs:
         ${{ steps.selective-checks.outputs.selected-providers-list-as-string }}
       skip-pre-commits: ${{ steps.selective-checks.outputs.skip-pre-commits }}
       skip-providers-tests: ${{ steps.selective-checks.outputs.skip-providers-tests }}
-      source-head-repo: ${{ steps.source-run-info.outputs.source-head-repo }}
+      source-head-repo: ${{ steps.source-run-info.outputs.head-repo }}
+      source-head-ref: ${{ steps.source-run-info.outputs.head-ref }}
       sqlite-exclude: ${{ steps.selective-checks.outputs.sqlite-exclude }}
       testable-core-integrations: ${{ steps.selective-checks.outputs.testable-core-integrations }}
       testable-providers-integrations: ${{ steps.selective-checks.outputs.testable-providers-integrations }}
@@ -309,6 +310,8 @@ jobs:
       default-postgres-version: ${{ needs.build-info.outputs.default-postgres-version }}
       run-coverage: ${{ needs.build-info.outputs.run-coverage }}
       use-uv: ${{ needs.build-info.outputs.use-uv }}
+      source-head-repo: ${{ needs.build-info.outputs.source-head-repo }}
+      source-head-ref: ${{ needs.build-info.outputs.source-head-ref }}
     secrets:
       DOCS_AWS_ACCESS_KEY_ID: ${{ secrets.DOCS_AWS_ACCESS_KEY_ID }}
       DOCS_AWS_SECRET_ACCESS_KEY: ${{ secrets.DOCS_AWS_SECRET_ACCESS_KEY }}
diff --git a/.github/workflows/ci-image-checks.yml b/.github/workflows/ci-image-checks.yml
index 8e1fc2991ca10..7fd13495aa827 100644
--- a/.github/workflows/ci-image-checks.yml
+++ b/.github/workflows/ci-image-checks.yml
@@ -104,6 +104,14 @@ on:  # yamllint disable-line rule:truthy
         description: "Whether to use uv to build the image (true/false)"
         required: true
         type: string
+      source-head-repo:
+        description: "The source head repository to use for back-references"
+        default: "apache/airflow"
+        type: string
+      source-head-ref:
+        description: "The source head ref to use for back-references"
+        default: "main"
+        type: string
     secrets:
       DOCS_AWS_ACCESS_KEY_ID:
         required: true
@@ -317,6 +325,8 @@ jobs:
       INCLUDE_SUCCESS_OUTPUTS: "${{ inputs.include-success-outputs }}"
       PYTHON_MAJOR_MINOR_VERSION: "${{ inputs.default-python-version }}"
       VERBOSE: "true"
+      HEAD_REPO: "${{ inputs.source-head-repo }}"
+      HEAD_REF: "${{ inputs.source-head-ref }}"
     steps:
       - name: "Cleanup repo"
         shell: bash
diff --git a/dev/breeze/doc/images/output_release-management_add-back-references.svg b/dev/breeze/doc/images/output_release-management_add-back-references.svg
index 0cdbd3a92eaa5..acd0a911ff6a8 100644
--- a/dev/breeze/doc/images/output_release-management_add-back-references.svg
+++ b/dev/breeze/doc/images/output_release-management_add-back-references.svg
@@ -1,4 +1,4 @@
-<svg class="rich-terminal" viewBox="0 0 1482 708.8" xmlns="http://www.w3.org/2000/svg">
+<svg class="rich-terminal" viewBox="0 0 1482 757.5999999999999" xmlns="http://www.w3.org/2000/svg">
     <!-- Generated with Rich https://www.textualize.io -->
     <style>
 
@@ -45,7 +45,7 @@
 
     <defs>
     <clipPath id="breeze-release-management-add-back-references-clip-terminal">
-      <rect x="0" y="0" width="1463.0" height="657.8" />
+      <rect x="0" y="0" width="1463.0" height="706.5999999999999" />
     </clipPath>
     <clipPath id="breeze-release-management-add-back-references-line-0">
     <rect x="0" y="1.5" width="1464" height="24.65"/>
@@ -125,9 +125,15 @@
 <clipPath id="breeze-release-management-add-back-references-line-25">
     <rect x="0" y="611.5" width="1464" height="24.65"/>
             </clipPath>
+<clipPath id="breeze-release-management-add-back-references-line-26">
+    <rect x="0" y="635.9" width="1464" height="24.65"/>
+            </clipPath>
+<clipPath id="breeze-release-management-add-back-references-line-27">
+    <rect x="0" y="660.3" width="1464" height="24.65"/>
+            </clipPath>
     </defs>
 
-    <rect fill="#292929" stroke="rgba(255,255,255,0.35)" stroke-width="1" x="1" y="1" width="1480" height="706.8" rx="8"/><text class="breeze-release-management-add-back-references-title" fill="#c5c8c6" text-anchor="middle" x="740" y="27">Command:&#160;release-management&#160;add-back-references</text>
+    <rect fill="#292929" stroke="rgba(255,255,255,0.35)" stroke-width="1" x="1" y="1" width="1480" height="755.6" rx="8"/><text class="breeze-release-management-add-back-references-title" fill="#c5c8c6" text-anchor="middle" x="740" y="27">Command:&#160;release-management&#160;add-back-references</text>
             <g transform="translate(26,22)">
             <circle cx="0" cy="0" r="7" fill="#ff5f57"/>
             <circle cx="22" cy="0" r="7" fill="#febc2e"/>
@@ -158,12 +164,14 @@
 </text><text class="breeze-release-management-add-back-references-r5" x="0" y="459.2" textLength="12.2" clip-path="url(#breeze-release-management-add-back-references-line-18)">│</text><text class="breeze-release-management-add-back-references-r6" x="24.4" y="459.2" textLength="12.2" clip-path="url(#breeze-release-management-add-back-references-line-18)">*</text><text class="breeze-release-management-add-back-references-r4" x="61" y="459.2" textLength="292.8" clip-path="url(#breeze-release-management-add-back-references-line-18)">--airflow-site-directory</text><text class="breeze-release-management-add-back-references-r7" x="439.2" y="459.2" textLength="24.4" clip-path="url(#breeze-release-management-add-back-references-line-18)">-a</text><text class="breeze-release-management-add-back-references-r1" x="488" y="459.2" textLength="597.8" clip-path="url(#breeze-release-management-add-back-references-line-18)">Local&#160;directory&#160;path&#160;of&#160;cloned&#160;airflow-site&#160;repo.</text><text class="breeze-release-management-add-back-references-r8" x="1098" y="459.2" textLength="134.2" clip-path="url(#breeze-release-management-add-back-references-line-18)">(DIRECTORY)</text><text class="breeze-release-management-add-back-references-r9" x="1244.4" y="459.2" textLength="122" clip-path="url(#breeze-release-management-add-back-references-line-18)">[required]</text><text class="breeze-release-management-add-back-references-r5" x="1451.8" y="459.2" textLength="12.2" clip-path="url(#breeze-release-management-add-back-references-line-18)">│</text><text class="breeze-release-management-add-back-references-r1" x="1464" y="459.2" textLength="12.2" clip-path="url(#breeze-release-management-add-back-references-line-18)">
 </text><text class="breeze-release-management-add-back-references-r5" x="0" y="483.6" textLength="12.2" clip-path="url(#breeze-release-management-add-back-references-line-19)">│</text><text class="breeze-release-management-add-back-references-r4" x="61" y="483.6" textLength="353.8" clip-path="url(#breeze-release-management-add-back-references-line-19)">--include-not-ready-providers</text><text class="breeze-release-management-add-back-references-r1" x="488" y="483.6" textLength="817.4" clip-path="url(#breeze-release-management-add-back-references-line-19)">Whether&#160;to&#160;include&#160;providers&#160;that&#160;are&#160;not&#160;yet&#160;ready&#160;to&#160;be&#160;released.</text><text class="breeze-release-management-add-back-references-r5" x="1451.8" y="483.6" textLength="12.2" clip-path="url(#breeze-release-management-add-back-references-line-19)">│</text><text class="breeze-release-management-add-back-references-r1" x="1464" y="483.6" textLength="12.2" clip-path="url(#breeze-release-management-add-back-references-line-19)">
 </text><text class="breeze-release-management-add-back-references-r5" x="0" y="508" textLength="12.2" clip-path="url(#breeze-release-management-add-back-references-line-20)">│</text><text class="breeze-release-management-add-back-references-r4" x="61" y="508" textLength="329.4" clip-path="url(#breeze-release-management-add-back-references-line-20)">--include-removed-providers</text><text class="breeze-release-management-add-back-references-r1" x="488" y="508" textLength="561.2" clip-path="url(#breeze-release-management-add-back-references-line-20)">Whether&#160;to&#160;include&#160;providers&#160;that&#160;are&#160;removed.</text><text class="breeze-release-management-add-back-references-r5" x="1451.8" y="508" textLength="12.2" clip-path="url(#breeze-release-management-add-back-references-line-20)">│</text><text class="breeze-release-management-add-back-references-r1" x="1464" y="508" textLength="12.2" clip-path="url(#breeze-release-management-add-back-references-line-20)">
-</text><text class="breeze-release-management-add-back-references-r5" x="0" y="532.4" textLength="1464" clip-path="url(#breeze-release-management-add-back-references-line-21)">╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯</text><text class="breeze-release-management-add-back-references-r1" x="1464" y="532.4" textLength="12.2" clip-path="url(#breeze-release-management-add-back-references-line-21)">
-</text><text class="breeze-release-management-add-back-references-r5" x="0" y="556.8" textLength="24.4" clip-path="url(#breeze-release-management-add-back-references-line-22)">╭─</text><text class="breeze-release-management-add-back-references-r5" x="24.4" y="556.8" textLength="195.2" clip-path="url(#breeze-release-management-add-back-references-line-22)">&#160;Common&#160;options&#160;</text><text class="breeze-release-management-add-back-references-r5" x="219.6" y="556.8" textLength="1220" clip-path="url(#breeze-release-management-add-back-references-line-22)">────────────────────────────────────────────────────────────────────────────────────────────────────</text><text class="breeze-release-management-add-back-references-r5" x="1439.6" y="556.8" textLength="24.4" clip-path="url(#breeze-release-management-add-back-references-line-22)">─╮</text><text class="breeze-release-management-add-back-references-r1" x="1464" y="556.8" textLength="12.2" clip-path="url(#breeze-release-management-add-back-references-line-22)">
-</text><text class="breeze-release-management-add-back-references-r5" x="0" y="581.2" textLength="12.2" clip-path="url(#breeze-release-management-add-back-references-line-23)">│</text><text class="breeze-release-management-add-back-references-r4" x="24.4" y="581.2" textLength="109.8" clip-path="url(#breeze-release-management-add-back-references-line-23)">--dry-run</text><text class="breeze-release-management-add-back-references-r7" x="158.6" y="581.2" textLength="24.4" clip-path="url(#breeze-release-management-add-back-references-line-23)">-D</text><text class="breeze-release-management-add-back-references-r1" x="207.4" y="581.2" textLength="719.8" clip-path="url(#breeze-release-management-add-back-references-line-23)">If&#160;dry-run&#160;is&#160;set,&#160;commands&#160;are&#160;only&#160;printed,&#160;not&#160;executed.</text><text class="breeze-release-management-add-back-references-r5" x="1451.8" y="581.2" textLength="12.2" clip-path="url(#breeze-release-management-add-back-references-line-23)">│</text><text class="breeze-release-management-add-back-references-r1" x="1464" y="581.2" textLength="12.2" clip-path="url(#breeze-release-management-add-back-references-line-23)">
-</text><text class="breeze-release-management-add-back-references-r5" x="0" y="605.6" textLength="12.2" clip-path="url(#breeze-release-management-add-back-references-line-24)">│</text><text class="breeze-release-management-add-back-references-r4" x="24.4" y="605.6" textLength="109.8" clip-path="url(#breeze-release-management-add-back-references-line-24)">--verbose</text><text class="breeze-release-management-add-back-references-r7" x="158.6" y="605.6" textLength="24.4" clip-path="url(#breeze-release-management-add-back-references-line-24)">-v</text><text class="breeze-release-management-add-back-references-r1" x="207.4" y="605.6" textLength="585.6" clip-path="url(#breeze-release-management-add-back-references-line-24)">Print&#160;verbose&#160;information&#160;about&#160;performed&#160;steps.</text><text class="breeze-release-management-add-back-references-r5" x="1451.8" y="605.6" textLength="12.2" clip-path="url(#breeze-release-management-add-back-references-line-24)">│</text><text class="breeze-release-management-add-back-references-r1" x="1464" y="605.6" textLength="12.2" clip-path="url(#breeze-release-management-add-back-references-line-24)">
-</text><text class="breeze-release-management-add-back-references-r5" x="0" y="630" textLength="12.2" clip-path="url(#breeze-release-management-add-back-references-line-25)">│</text><text class="breeze-release-management-add-back-references-r4" x="24.4" y="630" textLength="73.2" clip-path="url(#breeze-release-management-add-back-references-line-25)">--help</text><text class="breeze-release-management-add-back-references-r7" x="158.6" y="630" textLength="24.4" clip-path="url(#breeze-release-management-add-back-references-line-25)">-h</text><text class="breeze-release-management-add-back-references-r1" x="207.4" y="630" textLength="329.4" clip-path="url(#breeze-release-management-add-back-references-line-25)">Show&#160;this&#160;message&#160;and&#160;exit.</text><text class="breeze-release-management-add-back-references-r5" x="1451.8" y="630" textLength="12.2" clip-path="url(#breeze-release-management-add-back-references-line-25)">│</text><text class="breeze-release-management-add-back-references-r1" x="1464" y="630" textLength="12.2" clip-path="url(#breeze-release-management-add-back-references-line-25)">
-</text><text class="breeze-release-management-add-back-references-r5" x="0" y="654.4" textLength="1464" clip-path="url(#breeze-release-management-add-back-references-line-26)">╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯</text><text class="breeze-release-management-add-back-references-r1" x="1464" y="654.4" textLength="12.2" clip-path="url(#breeze-release-management-add-back-references-line-26)">
+</text><text class="breeze-release-management-add-back-references-r5" x="0" y="532.4" textLength="12.2" clip-path="url(#breeze-release-management-add-back-references-line-21)">│</text><text class="breeze-release-management-add-back-references-r4" x="61" y="532.4" textLength="134.2" clip-path="url(#breeze-release-management-add-back-references-line-21)">--head-repo</text><text class="breeze-release-management-add-back-references-r1" x="488" y="532.4" textLength="488" clip-path="url(#breeze-release-management-add-back-references-line-21)">The&#160;repository&#160;of&#160;redirect&#160;files&#160;to&#160;use.</text><text class="breeze-release-management-add-back-references-r8" x="988.2" y="532.4" textLength="73.2" clip-path="url(#breeze-release-management-add-back-references-line-21)">(TEXT)</text><text class="breeze-release-management-add-back-references-r5" x="1073.6" y="532.4" textLength="305" clip-path="url(#breeze-release-management-add-back-references-line-21)">[default:&#160;apache/airflow]</text><text class="breeze-release-management-add-back-references-r5" x="1451.8" y="532.4" textLength="12.2" clip-path="url(#breeze-release-management-add-back-references-line-21)">│</text><text class="breeze-release-management-add-back-references-r1" x="1464" y="532.4" textLength="12.2" clip-path="url(#breeze-release-management-add-back-references-line-21)">
+</text><text class="breeze-release-management-add-back-references-r5" x="0" y="556.8" textLength="12.2" clip-path="url(#breeze-release-management-add-back-references-line-22)">│</text><text class="breeze-release-management-add-back-references-r4" x="61" y="556.8" textLength="122" clip-path="url(#breeze-release-management-add-back-references-line-22)">--head-ref</text><text class="breeze-release-management-add-back-references-r1" x="488" y="556.8" textLength="439.2" clip-path="url(#breeze-release-management-add-back-references-line-22)">The&#160;branch&#160;of&#160;redirect&#160;files&#160;to&#160;use.</text><text class="breeze-release-management-add-back-references-r8" x="939.4" y="556.8" textLength="73.2" clip-path="url(#breeze-release-management-add-back-references-line-22)">(TEXT)</text><text class="breeze-release-management-add-back-references-r5" x="1024.8" y="556.8" textLength="244" clip-path="url(#breeze-release-management-add-back-references-line-22)">[default:&#160;v3-0-test]</text><text class="breeze-release-management-add-back-references-r5" x="1451.8" y="556.8" textLength="12.2" clip-path="url(#breeze-release-management-add-back-references-line-22)">│</text><text class="breeze-release-management-add-back-references-r1" x="1464" y="556.8" textLength="12.2" clip-path="url(#breeze-release-management-add-back-references-line-22)">
+</text><text class="breeze-release-management-add-back-references-r5" x="0" y="581.2" textLength="1464" clip-path="url(#breeze-release-management-add-back-references-line-23)">╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯</text><text class="breeze-release-management-add-back-references-r1" x="1464" y="581.2" textLength="12.2" clip-path="url(#breeze-release-management-add-back-references-line-23)">
+</text><text class="breeze-release-management-add-back-references-r5" x="0" y="605.6" textLength="24.4" clip-path="url(#breeze-release-management-add-back-references-line-24)">╭─</text><text class="breeze-release-management-add-back-references-r5" x="24.4" y="605.6" textLength="195.2" clip-path="url(#breeze-release-management-add-back-references-line-24)">&#160;Common&#160;options&#160;</text><text class="breeze-release-management-add-back-references-r5" x="219.6" y="605.6" textLength="1220" clip-path="url(#breeze-release-management-add-back-references-line-24)">────────────────────────────────────────────────────────────────────────────────────────────────────</text><text class="breeze-release-management-add-back-references-r5" x="1439.6" y="605.6" textLength="24.4" clip-path="url(#breeze-release-management-add-back-references-line-24)">─╮</text><text class="breeze-release-management-add-back-references-r1" x="1464" y="605.6" textLength="12.2" clip-path="url(#breeze-release-management-add-back-references-line-24)">
+</text><text class="breeze-release-management-add-back-references-r5" x="0" y="630" textLength="12.2" clip-path="url(#breeze-release-management-add-back-references-line-25)">│</text><text class="breeze-release-management-add-back-references-r4" x="24.4" y="630" textLength="109.8" clip-path="url(#breeze-release-management-add-back-references-line-25)">--dry-run</text><text class="breeze-release-management-add-back-references-r7" x="158.6" y="630" textLength="24.4" clip-path="url(#breeze-release-management-add-back-references-line-25)">-D</text><text class="breeze-release-management-add-back-references-r1" x="207.4" y="630" textLength="719.8" clip-path="url(#breeze-release-management-add-back-references-line-25)">If&#160;dry-run&#160;is&#160;set,&#160;commands&#160;are&#160;only&#160;printed,&#160;not&#160;executed.</text><text class="breeze-release-management-add-back-references-r5" x="1451.8" y="630" textLength="12.2" clip-path="url(#breeze-release-management-add-back-references-line-25)">│</text><text class="breeze-release-management-add-back-references-r1" x="1464" y="630" textLength="12.2" clip-path="url(#breeze-release-management-add-back-references-line-25)">
+</text><text class="breeze-release-management-add-back-references-r5" x="0" y="654.4" textLength="12.2" clip-path="url(#breeze-release-management-add-back-references-line-26)">│</text><text class="breeze-release-management-add-back-references-r4" x="24.4" y="654.4" textLength="109.8" clip-path="url(#breeze-release-management-add-back-references-line-26)">--verbose</text><text class="breeze-release-management-add-back-references-r7" x="158.6" y="654.4" textLength="24.4" clip-path="url(#breeze-release-management-add-back-references-line-26)">-v</text><text class="breeze-release-management-add-back-references-r1" x="207.4" y="654.4" textLength="585.6" clip-path="url(#breeze-release-management-add-back-references-line-26)">Print&#160;verbose&#160;information&#160;about&#160;performed&#160;steps.</text><text class="breeze-release-management-add-back-references-r5" x="1451.8" y="654.4" textLength="12.2" clip-path="url(#breeze-release-management-add-back-references-line-26)">│</text><text class="breeze-release-management-add-back-references-r1" x="1464" y="654.4" textLength="12.2" clip-path="url(#breeze-release-management-add-back-references-line-26)">
+</text><text class="breeze-release-management-add-back-references-r5" x="0" y="678.8" textLength="12.2" clip-path="url(#breeze-release-management-add-back-references-line-27)">│</text><text class="breeze-release-management-add-back-references-r4" x="24.4" y="678.8" textLength="73.2" clip-path="url(#breeze-release-management-add-back-references-line-27)">--help</text><text class="breeze-release-management-add-back-references-r7" x="158.6" y="678.8" textLength="24.4" clip-path="url(#breeze-release-management-add-back-references-line-27)">-h</text><text class="breeze-release-management-add-back-references-r1" x="207.4" y="678.8" textLength="329.4" clip-path="url(#breeze-release-management-add-back-references-line-27)">Show&#160;this&#160;message&#160;and&#160;exit.</text><text class="breeze-release-management-add-back-references-r5" x="1451.8" y="678.8" textLength="12.2" clip-path="url(#breeze-release-management-add-back-references-line-27)">│</text><text class="breeze-release-management-add-back-references-r1" x="1464" y="678.8" textLength="12.2" clip-path="url(#breeze-release-management-add-back-references-line-27)">
+</text><text class="breeze-release-management-add-back-references-r5" x="0" y="703.2" textLength="1464" clip-path="url(#breeze-release-management-add-back-references-line-28)">╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯</text><text class="breeze-release-management-add-back-references-r1" x="1464" y="703.2" textLength="12.2" clip-path="url(#breeze-release-management-add-back-references-line-28)">
 </text>
     </g>
     </g>
diff --git a/dev/breeze/doc/images/output_release-management_add-back-references.txt b/dev/breeze/doc/images/output_release-management_add-back-references.txt
index d836dfac06271..d85b6b2c22d21 100644
--- a/dev/breeze/doc/images/output_release-management_add-back-references.txt
+++ b/dev/breeze/doc/images/output_release-management_add-back-references.txt
@@ -1 +1 @@
-e9a2d362c309bde38992498e732bccfb
+046f2fbe2d8e77a2f4a8be3f6a27497e
diff --git a/dev/breeze/src/airflow_breeze/commands/ci_commands.py b/dev/breeze/src/airflow_breeze/commands/ci_commands.py
index a5453794a31f9..0c33e11b828a5 100644
--- a/dev/breeze/src/airflow_breeze/commands/ci_commands.py
+++ b/dev/breeze/src/airflow_breeze/commands/ci_commands.py
@@ -285,6 +285,7 @@ class WorkflowInfo(NamedTuple):
     ref: str | None
     ref_name: str | None
     pr_number: int | None
+    head_ref: str | None = None
 
     def get_all_ga_outputs(self) -> Iterable[str]:
         from airflow_breeze.utils.github import get_ga_output
@@ -297,6 +298,7 @@ def get_all_ga_outputs(self) -> Iterable[str]:
         yield get_ga_output(name="runs-on", value=self.get_runs_on())
         yield get_ga_output(name="canary-run", value=self.is_canary_run())
         yield get_ga_output(name="run-coverage", value=self.run_coverage())
+        yield get_ga_output(name="head-ref", value=self.head_ref)
 
     def print_all_ga_outputs(self):
         for output in self.get_all_ga_outputs():
@@ -348,6 +350,7 @@ def workflow_info(context: str) -> WorkflowInfo:
     pr_number: int | None = None
     ref_name = ctx.get("ref_name")
     ref = ctx.get("ref")
+    head_ref = ctx.get("head_ref")
     if event_name == GithubEvents.PULL_REQUEST.value:
         event = ctx.get("event")
         if event:
@@ -387,6 +390,7 @@ def workflow_info(context: str) -> WorkflowInfo:
         pr_number=pr_number,
         ref=ref,
         ref_name=ref_name,
+        head_ref=head_ref,
     )
 
 
diff --git a/dev/breeze/src/airflow_breeze/commands/release_management_commands.py b/dev/breeze/src/airflow_breeze/commands/release_management_commands.py
index ed60c1e0a09fe..dcfe531df4c7e 100644
--- a/dev/breeze/src/airflow_breeze/commands/release_management_commands.py
+++ b/dev/breeze/src/airflow_breeze/commands/release_management_commands.py
@@ -44,6 +44,7 @@
 from rich.progress import Progress
 from rich.syntax import Syntax
 
+from airflow_breeze.branch_defaults import AIRFLOW_BRANCH
 from airflow_breeze.commands.ci_image_commands import rebuild_or_pull_ci_image_if_needed
 from airflow_breeze.commands.common_options import (
     argument_doc_packages,
@@ -1884,12 +1885,35 @@ def publish_docs(
 @argument_doc_packages
 @option_dry_run
 @option_verbose
+@click.option(
+    "--head-ref",
+    help="The branch of redirect files to use.",
+    default=AIRFLOW_BRANCH,
+    envvar="HEAD_REF",
+    show_default=True,
+)
+@click.option(
+    "--head-repo",
+    help="The repository of redirect files to use.",
+    default=APACHE_AIRFLOW_GITHUB_REPOSITORY,
+    envvar="HEAD_REPO",
+    show_default=True,
+)
 def add_back_references(
     airflow_site_directory: str,
     include_not_ready_providers: bool,
     include_removed_providers: bool,
     doc_packages: tuple[str, ...],
+    head_ref: str,
+    head_repo: str,
 ):
+    # head_ref and head_repo could be empty in canary runs
+
+    if head_ref == "":
+        head_ref = AIRFLOW_BRANCH
+    if head_repo == "":
+        head_repo = APACHE_AIRFLOW_GITHUB_REPOSITORY
+
     """Adds back references for documentation generated by build-docs and publish-docs"""
     site_path = Path(airflow_site_directory)
     if not site_path.is_dir():
@@ -1912,6 +1936,8 @@ def add_back_references(
                 include_not_ready=include_not_ready_providers,
             )
         ),
+        head_ref=head_ref,
+        head_repo=head_repo,
     )
 
 
diff --git a/dev/breeze/src/airflow_breeze/commands/release_management_commands_config.py b/dev/breeze/src/airflow_breeze/commands/release_management_commands_config.py
index 2bcfb5cb57941..14e331a3271b4 100644
--- a/dev/breeze/src/airflow_breeze/commands/release_management_commands_config.py
+++ b/dev/breeze/src/airflow_breeze/commands/release_management_commands_config.py
@@ -382,6 +382,8 @@
                 "--airflow-site-directory",
                 "--include-not-ready-providers",
                 "--include-removed-providers",
+                "--head-repo",
+                "--head-ref",
             ],
         },
     ],
diff --git a/dev/breeze/src/airflow_breeze/utils/add_back_references.py b/dev/breeze/src/airflow_breeze/utils/add_back_references.py
index 6a9896c5da541..966a5944f97fb 100644
--- a/dev/breeze/src/airflow_breeze/utils/add_back_references.py
+++ b/dev/breeze/src/airflow_breeze/utils/add_back_references.py
@@ -26,9 +26,10 @@
 from airflow_breeze.utils.console import get_console
 
 airflow_redirects_link = (
-    "https://raw.githubusercontent.com/apache/airflow/main/airflow-core/docs/redirects.txt"
+    "https://raw.githubusercontent.com/{head_repo}/{head_ref}/airflow-core/docs/redirects.txt"
 )
-helm_redirects_link = "https://raw.githubusercontent.com/apache/airflow/main/docs/helm-chart/redirects.txt"
+
+helm_redirects_link = "https://raw.githubusercontent.com/{head_repo}/{head_ref}/docs/helm-chart/redirects.txt"
 
 
 def download_file(url):
@@ -64,10 +65,10 @@ def get_redirect_content(url: str):
     return f'<html><head><meta http-equiv="refresh" content="0; url={url}"/></head></html>'
 
 
-def get_github_provider_redirects_url(provider_name: str):
-    return (
-        f"https://raw.githubusercontent.com/apache/airflow/main/providers/{provider_name}/docs/redirects.txt"
-    )
+def get_github_provider_redirects_url(
+    provider_name: str, head_repo: str = "apache/airflow", head_ref: str = "main"
+) -> str:
+    return f"https://raw.githubusercontent.com/{head_repo}/{head_ref}/providers/{provider_name}/docs/redirects.txt"
 
 
 def crete_redirect_html_if_not_exist(path: Path, content: str):
@@ -133,15 +134,20 @@ def generate_back_references(link: str, base_path: Path):
 def start_generating_back_references(
     airflow_site_directory: Path,
     short_provider_ids: list[str],
+    head_repo: str = "apache/airflow",
+    head_ref: str = "main",
 ):
+    airflow_redirects_url = airflow_redirects_link.format(head_repo=head_repo, head_ref=head_ref)
+    helm_redirects_url = helm_redirects_link.format(head_repo=head_repo, head_ref=head_ref)
+
     docs_archive_path = airflow_site_directory / "docs-archive"
     airflow_docs_path = docs_archive_path / "apache-airflow"
     helm_docs_path = docs_archive_path / "helm-chart"
     if "apache-airflow" in short_provider_ids:
-        generate_back_references(airflow_redirects_link, airflow_docs_path)
+        generate_back_references(airflow_redirects_url, airflow_docs_path)
         short_provider_ids.remove("apache-airflow")
     if "helm-chart" in short_provider_ids:
-        generate_back_references(helm_redirects_link, helm_docs_path)
+        generate_back_references(helm_redirects_url, helm_docs_path)
         short_provider_ids.remove("helm-chart")
     if "docker-stack" in short_provider_ids:
         get_console().print("[info]Skipping docker-stack package. No back-reference needed.")
@@ -155,6 +161,6 @@ def start_generating_back_references(
             full_provider_name = f"apache-airflow-providers-{p.replace('.', '-')}"
             get_console().print(f"Processing airflow provider: {full_provider_name}")
             generate_back_references(
-                get_github_provider_redirects_url(slash_based_short_provider_id),
+                get_github_provider_redirects_url(slash_based_short_provider_id, head_repo, head_ref),
                 docs_archive_path / full_provider_name,
             )
