Preheat oven to 375°F (190°C). Boil green beans 5-6 minutes until crisp-tender; drain and set aside.
Cook bacon in a skillet until crisp. Remove bacon, leaving 1 tbsp drippings.
Sauté onion in drippings with butter until soft, about 4 minutes. Add garlic and cook 30 seconds.
Stir in flour, then whisk in milk until thickened, about 2 minutes.
Remove from heat; stir in cheddar, sour cream, bacon, salt, and pepper.
Toss sauce with green beans in a baking dish. Top with crispy fried onions.
Bake 15-18 minutes until bubbly and lightly browned on top.