diff --git a/gems/gitlab-housekeeper/lib/gitlab/housekeeper/git.rb b/gems/gitlab-housekeeper/lib/gitlab/housekeeper/git.rb
index 329d32885eeefd3c4da3f42beb41f26110057f1b..cb2a8154d85a01ed8475aa7e21ba77110c3555da 100644
--- a/gems/gitlab-housekeeper/lib/gitlab/housekeeper/git.rb
+++ b/gems/gitlab-housekeeper/lib/gitlab/housekeeper/git.rb
@@ -30,7 +30,9 @@ def with_branch_from_branch
 
         yield
       ensure
-        Shell.execute("git", "checkout", current_branch)
+        # The `current_branch` won't be set in CI due to how the repo is cloned. Therefore we should only checkout
+        # `current_branch` if we actually have one.
+        Shell.execute("git", "checkout", current_branch) if current_branch.present?
         Shell.execute('git', 'stash', 'pop') if stashed
       end
 
diff --git a/keeps/overdue_finalize_background_migration.rb b/keeps/overdue_finalize_background_migration.rb
index 035db201b4857a809ec134b64f8798e9f1da545a..02dc33c4d63186926d79680b73b85de1bb3b1a53 100644
--- a/keeps/overdue_finalize_background_migration.rb
+++ b/keeps/overdue_finalize_background_migration.rb
@@ -3,6 +3,7 @@
 require_relative '../config/environment'
 require_relative '../lib/generators/post_deployment_migration/post_deployment_migration_generator'
 require_relative './helpers/postgres_ai'
+require 'rubocop'
 
 module Keeps
   # This is an implementation of a ::Gitlab::Housekeeper::Keep. This keep will locate any old batched background