diff --git a/routers/web/repo/view_home.go b/routers/web/repo/view_home.go
index 3fcd7bba8e..f890225d67 100644
--- a/routers/web/repo/view_home.go
+++ b/routers/web/repo/view_home.go
@@ -250,6 +250,7 @@ func handleRepoEmptyOrBroken(ctx *context.Context) {
showEmpty = true // it is not really empty, but there is no branch
// at the moment, other repo units like "actions" are not able to handle such case,
// so we just mark the repo as empty to prevent from displaying these units.
+ ctx.Data["RepoHasContentsWithoutBranch"] = true
updateContextRepoEmptyAndStatus(ctx, true, repo_model.RepositoryReady)
} else {
// the repo is actually not empty and has branches, need to update the database later
diff --git a/templates/repo/empty.tmpl b/templates/repo/empty.tmpl
index dfda5b7b2b..ae3f95045b 100644
--- a/templates/repo/empty.tmpl
+++ b/templates/repo/empty.tmpl
@@ -17,7 +17,7 @@
{{if .Repository.IsBroken}}
{{ctx.Locale.Tr "repo.broken_message"}}
- {{else if .Repository.IsEmpty}}
+ {{else if .RepoHasContentsWithoutBranch}}
{{ctx.Locale.Tr "repo.no_branch"}}
{{else if .CanWriteCode}}
diff --git a/tests/integration/empty_repo_test.go b/tests/integration/empty_repo_test.go
index 630a3c03af..0801b093df 100644
--- a/tests/integration/empty_repo_test.go
+++ b/tests/integration/empty_repo_test.go
@@ -58,8 +58,12 @@ func TestEmptyRepoAddFile(t *testing.T) {
defer tests.PrepareTestEnv(t)()
session := loginUser(t, "user30")
- req := NewRequest(t, "GET", "/user30/empty/_new/"+setting.Repository.DefaultBranch)
+ req := NewRequest(t, "GET", "/user30/empty")
resp := session.MakeRequest(t, req, http.StatusOK)
+ assert.Contains(t, resp.Body.String(), "empty-repo-guide")
+
+ req = NewRequest(t, "GET", "/user30/empty/_new/"+setting.Repository.DefaultBranch)
+ resp = session.MakeRequest(t, req, http.StatusOK)
doc := NewHTMLParser(t, resp.Body).Find(`input[name="commit_choice"]`)
assert.Empty(t, doc.AttrOr("checked", "_no_"))
req = NewRequestWithValues(t, "POST", "/user30/empty/_new/"+setting.Repository.DefaultBranch, map[string]string{