Wash the beet greens. Trim the leaves from the ribs. Cut the ribs into 1/4-inch pieces.
Bring a large pot of salted water to a boil. Following package directions, cook the spaghetti until it is tender to the bite (al dente).
Over medium high flame, heat the oil in a large skillet.
Add the onion and beet stems and cook and stir until the beet stems soften a bit. Add the garlic, if you are not using basil pesto.
Chop the beet greens into 1-inch ribbons and add to the skillet. Reduce the heat and cook, stirring occasionally, until the greens wilt and shrink, about 10 minutes. Season with the sherry wine vinegar and salt.
Stir in the pesto, and red chile flakes, and then gently toss in the cooked spaghetti, stirring to mix well.
Vegans: do not use pesto as it contains cheese. Sauté 3 minced garlic cloves with the onion and beet stem mix.