Not familiar with selling one property and buying another to avoid capital gains the same year. You can avoid CG if you lived on the property for at least 2 of the last 5 years and you can use the $250,000/$500,000 rule to avoid quite a bit.
Just closed on a property last month that I lived in so no CG.
I have 2 more houses that will go on the market next month, that I never lived in. My goal is to run them through a 1031 exchange. And purchase a multifamily when they sell. That involves doing the paperwork before they close, then when they do close the money goes directly into a type of trust, I’ll have 45 days from the day of closing to identify the property I wish to purchase, and 180 days from the time of closing the original property, to close on the new property. By doing that I avoid capital gains and move up in the income I will get from the new property. It has to meet certain requirements which is pretty simple, but it’s a great way to create generational wealth, in my case that’s using the term loosely. You do have to spend every dollar of what you get or more which is pretty easy when you are moving up. It was built into tax laws for politicians to create generational wealth, it’s possible to repeat this over the years. You can sell residential property and buy commercial property as well.