In a large bowl, combine the ricotta, 1 cup of the flour, the egg, and 1 teaspoon salt; stir with a wooden spoon until combined.
Add up to the remaining 1 cup of flour, 1/4 cup at a time, mixing after each addition until a smooth, slightly sticky dough forms.
Turn the dough onto a well-floured surface and knead briefly, adding more flour as needed until the dough comes together, is smooth, and slightly elastic (about 1–2 minutes).
Form the dough into a ball, wrap it in plastic, and refrigerate for 30 minutes.
Divide the chilled dough into 8 equal pieces. Working with one piece at a time, roll it into a rope about the diameter of your finger and cut into 1/2-inch pieces.
Roll each piece over the back of a fork if desired to create ridges, then transfer to a parchment-lined baking sheet while you shape the rest.
Bring a large pot of well-salted water to a boil. Cook the gnocchi in batches for 3–5 minutes until they float and cook for at least 1–2 minutes after floating; timing may vary by size.
Drain the gnocchi and set aside while you finish the sauce or serve immediately with marinara.
For the marinara: heat the olive oil in a skillet, add the garlic cloves and cook until slightly golden, then add the chopped onion and cook until soft.
Stir in the tomato paste and cook briefly, then carefully add the canned tomatoes (watch for splatter). Add a pinch of sugar, basil, oregano, and salt and pepper to taste.
Simmer the sauce for about 30 minutes, remove the whole garlic cloves, and serve the marinara over the cooked gnocchi.