diff --git a/scripts/run-docs-build b/scripts/run-docs-build
index 549032f..654b401 100755
--- a/scripts/run-docs-build
+++ b/scripts/run-docs-build
@@ -138,7 +138,11 @@ for branch in 1.46 $(git branch --remote --contains "$first_sphinx_commit" --for
     git checkout $branch
     git reset --hard
     git clean -ffdx
-    git checkout origin/master releases.rst set_versions.py sphinx-static/switchers.js.in Makefile
+    git checkout origin/master releases.rst set_versions.py sphinx-static/switchers.js.in Makefile conf.py
+
+    # Pass this information to Bitbake so the docs gets built on the proper
+    # version. See bitbake/doc/conf.py.
+    export BITBAKE_CURRENT_VERSION="$branch"
 
     (
         . $builddir/buildtools/environment-setup*
@@ -213,7 +217,7 @@ for branch in "$ypdocsbranch" dunfell $(git branch --remote --contains "$first_s
         git am "${scriptdir}/docs-build-patches/${branch}/"000*
     fi
 
-    git checkout origin/master sphinx-static/switchers.js.in set_versions.py
+    git checkout tmp sphinx-static/switchers.js.in set_versions.py Makefile
     if [ -e poky.yaml ]; then
         cp poky.yaml poky.yaml.in
         case $branch in
