diff --git a/app/models/repository.rb b/app/models/repository.rb
index 89293fa8b4dec160b101443a0d162e7d2534fe71..c4bdc84348ea0ef07361b085a74be1669afb5554 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -901,10 +901,15 @@ class Repository
       branch,
       source_branch: source_branch) do |ref|
       index = rugged.index
-
-      last_commit = find_branch(ref).dereferenced_target
-      index.read_tree(last_commit.raw_commit.tree)
-      parents = [last_commit.sha]
+      branch_commit = find_branch(ref)
+
+      parents = if branch_commit
+                  last_commit = branch_commit.dereferenced_target
+                  index.read_tree(last_commit.raw_commit.tree)
+                  [last_commit.sha]
+                else
+                  []
+                end
 
       actions.each do |action|
         case action[:action]