diff --git a/modules/repository/init.go b/modules/repository/init.go index 8f3f2f05906e..5bdfa7490d81 100644 --- a/modules/repository/init.go +++ b/modules/repository/init.go @@ -214,6 +214,13 @@ func initRepository(ctx models.DBContext, repoPath string, u *models.User, repo repo.DefaultBranch = "master" if len(opts.DefaultBranch) > 0 { repo.DefaultBranch = opts.DefaultBranch + gitRepo, err := git.OpenRepository(repo.RepoPath()) + if err != nil { + return fmt.Errorf("openRepository: %v", err) + } + if err = gitRepo.SetDefaultBranch(repo.DefaultBranch); err != nil { + return fmt.Errorf("setDefaultBranch: %v", err) + } } if err = models.UpdateRepositoryCtx(ctx, repo, false); err != nil {