Melt 2 tablespoons butter in a large skillet over medium-low heat. Add in onion and garlic and cook til onion is translucent. Scoop out as much onion and garlic as you can, and set aside. Add butter back into pan until it's at about 2 tbsp again. Stir in flour until smooth, and cook for one minute. Stir in the salt, sugar, and sour cream. Add green beans (without the water from the can) and cooked onions and garlic, and stir to coat.
Transfer the mixture to a 2 1/2 quart casserole dish. Sprinkle half the cheese in and stir to combine, then spread remaining cheese over the top. In a small bowl, toss together cracker crumbs and remaining butter, and sprinkle over the cheese. If you're using french fried onions too, crumble half the package over the casserole.
Bake for 30 minutes in the preheated oven, or until the top is golden and cheese is bubbly.