You may not consider this a fair answer to the original question, but one way to do it is to not do it.
Meaning that one way to solve the problem of buying a new house before selling an old house is to avoid getting into that situation. What I have always done is sell the old house, pay off any mortgage, stick the rest of the remaining equity into a savings account, then go shopping for and buy a new house. If the timing doesn't line up well enough, then rent an apartment for a few months.
Yes, you'll move twice and may have to live in a smaller place for a bit. So what? Yes, you may not get to buy that "perfect" house before it gets sold to someone else. It isn't wise to fall in love with any particular house anyway - you'll end up paying too much for it (been there, done that, got the T-shirt).
On the plus side, you won't have cash flow problems or recast fees or spend a boatload of money on mortgage interest and you might save some origination fees on a mortgage or HELOC that you won't have to get.
Not meaning to sound obnoxious or superior, just wanting to point out another option that hadn't been mentioned yet on this thread and some of its pros and cons.