Preheat the oven to 350 degrees F (175 degrees C).
Melt butter in a saucepan over medium heat; cook and stir onion and garlic until onion becomes translucent, 2 to 3 minutes.
Cook and stir refried beans into onion mixture until heated through, 3 to 5 minutes. Remove from heat and stir cream cheese into bean mixture. Spread mixture into a pie plate; top with Cheddar cheese.
Bake in the preheated oven until cheese is melted and bubbling, about 20 minutes.