Yes, and in many cases, you should. If you keep your home during the bankruptcy and do not reaffirm the debt, any later on-time payments will not be reflected on your credit report. This is due to a technical issue regarding the severability of mortgages and the note, and how debts are reported to the credit reporting agencies. However, paying off the existing mortgage and refinancing will have a much greater effect in rebuilding your credit.
Because bankruptcy (and often, the financial difficulties which gave rise to a bankruptcy filing) will make it difficult to obtain credit, many people will find it difficult to refinance immediately after bankruptcy. However, taking steps to repair credit (such as establishing a good repayment history on other reaffirmed debts or a secured credit card, maintaining a cash reserve, paying debts on time, and borrowing and repaying a small personal loan) can accelerate credit repair. If you take the proper steps to rebuild your credit following bankruptcy, you may be able to qualify for a refinance loan in as little as 2 years after your discharge.