diff --git a/internal/git/housekeeping/commit_graph.go b/internal/git/housekeeping/commit_graph.go
index 9e5b406b241efb4bbd30115e720b328719de5f46..2476083e1b5caef82f065c29b79aa158f8df2eaa 100644
--- a/internal/git/housekeeping/commit_graph.go
+++ b/internal/git/housekeeping/commit_graph.go
@@ -7,6 +7,7 @@ import (
 	"gitlab.com/gitlab-org/gitaly/v15/internal/git"
 	"gitlab.com/gitlab-org/gitaly/v15/internal/git/localrepo"
 	"gitlab.com/gitlab-org/gitaly/v15/internal/git/stats"
+	"gitlab.com/gitlab-org/gitaly/v15/internal/metadata/featureflag"
 	"gitlab.com/gitlab-org/gitaly/v15/internal/structerr"
 )
 
@@ -45,6 +46,9 @@ func WriteCommitGraphConfigForRepository(ctx context.Context, repo *localrepo.Re
 		// ain't got bloom filters enabled. This is because Git will refuse to write any
 		// bloom filters as long as any of the commit-graph slices is missing this info.
 		replaceChain = true
+	} else if !commitGraphInfo.HasGenerationData && featureflag.UseCommitGraphGenerationData.IsEnabled(ctx) {
+		// The same is true for generation data.
+		replaceChain = true
 	}
 
 	return WriteCommitGraphConfig{
diff --git a/internal/git/housekeeping/commit_graph_test.go b/internal/git/housekeeping/commit_graph_test.go
index f3e323702c14a01dd7d50bf72b8469d4e266cc7c..d95af04d17da0091b42d62a211f68dac0a7a3a18 100644
--- a/internal/git/housekeeping/commit_graph_test.go
+++ b/internal/git/housekeeping/commit_graph_test.go
@@ -1,19 +1,25 @@
 package housekeeping
 
 import (
+	"context"
 	"testing"
 
 	"github.com/stretchr/testify/require"
 	"gitlab.com/gitlab-org/gitaly/v15/internal/git/gittest"
 	"gitlab.com/gitlab-org/gitaly/v15/internal/git/localrepo"
+	"gitlab.com/gitlab-org/gitaly/v15/internal/metadata/featureflag"
 	"gitlab.com/gitlab-org/gitaly/v15/internal/testhelper"
 	"gitlab.com/gitlab-org/gitaly/v15/internal/testhelper/testcfg"
 )
 
 func TestWriteCommitGraphConfigForRepository(t *testing.T) {
 	t.Parallel()
+	testhelper.NewFeatureSets(featureflag.UseCommitGraphGenerationData).Run(t, testWriteCommitGraphConfigForRepository)
+}
+
+func testWriteCommitGraphConfigForRepository(t *testing.T, ctx context.Context) {
+	t.Parallel()
 
-	ctx := testhelper.Context(t)
 	cfg := testcfg.Build(t)
 
 	for _, tc := range []struct {
@@ -62,10 +68,26 @@ func TestWriteCommitGraphConfigForRepository(t *testing.T) {
 			},
 		},
 		{
-			desc: "split commit-graph with bloom filter",
+			desc: "split commit-graph with bloom filter without generation data",
+			setup: func(t *testing.T, repoPath string) {
+				gittest.WriteCommit(t, cfg, repoPath, gittest.WithBranch("main"))
+				gittest.Exec(t, cfg, "-C", repoPath,
+					"-c", "commitGraph.generationVersion=1",
+					"commit-graph", "write", "--reachable", "--split", "--changed-paths",
+				)
+			},
+			expectedConfig: WriteCommitGraphConfig{
+				ReplaceChain: featureflag.UseCommitGraphGenerationData.IsEnabled(ctx),
+			},
+		},
+		{
+			desc: "split commit-graph with bloom filter with generation data",
 			setup: func(t *testing.T, repoPath string) {
 				gittest.WriteCommit(t, cfg, repoPath, gittest.WithBranch("main"))
-				gittest.Exec(t, cfg, "-C", repoPath, "commit-graph", "write", "--reachable", "--split", "--changed-paths")
+				gittest.Exec(t, cfg, "-C", repoPath,
+					"-c", "commitGraph.generationVersion=2",
+					"commit-graph", "write", "--reachable", "--split", "--changed-paths",
+				)
 			},
 			expectedConfig: WriteCommitGraphConfig{
 				ReplaceChain: false,