diff --git a/app/controllers/projects/badges_controller.rb b/app/controllers/projects/badges_controller.rb
index 9dff74c823bd7c228c54bd5b4ebeeee496066ebb..824aa41db51c7145140ba00f50aabc6f5abca9cc 100644
--- a/app/controllers/projects/badges_controller.rb
+++ b/app/controllers/projects/badges_controller.rb
@@ -4,7 +4,7 @@ class Projects::BadgesController < Projects::ApplicationController
   before_action :no_cache_headers, except: [:index]
 
   def index
-    @ref = params[:ref] || 'master'
+    @ref = params[:ref] || @project.default_branch || 'master'
     @build_badge = Gitlab::Badge::Build.new(@project, @ref)
   end