When most debtors understand that you can keep your home in the Chapter 7 bankruptcy, they begin asking how. In Chapter 7, there are really two options: reaffirm, or more informally, pay and retain. A reaffirmation agreement is one that essentially reobligates your obligation to the loan. Whereas the filing of the bankruptcy discharges your liability to the secured mortgage debt, the reaffirmation agreement reinstates that obligation through the bankruptcy. Often, these agreements are sent by the mortgage company to be filled out by the debtor and/or the debtor's attorney, sent back to the creditor, and then filed with the court.
Once a reaffirmation agreement is signed, and assuming that it doesn't get rescinded before the discharge, the debtor is liable to that mortgage debt as if no bankruptcy had ever been filed. The benefits to this are that you get positive credit history post bankruptcy and it makes it much easier to refinance down the line.
The problem with reaffirming on a mortgage occur when the loan is underwater to the value of the home. This essentially means that you give yourself added debt compared to the value of the home the second you reaffirm on that loan. In these situations, considering that it is probably advisable to surrender your interest in the home, or you'll never be able to refinance down the road anyways because of a lack of equity, it is probably best to simply pay and retain on the mortgage. In these situations, you are discharged from the obligation to pay the mortgage debt after the bankruptcy but keep the property as long as the mortgage remains current. Should the situation ever arise, you can let the home go in foreclosure and still be discharged from any deficiency balance, even if it is years after the bankruptcy filing.
Reaffirmations are required for other certain, smaller secured debts like vehicles and various purchase money security interests. They can be complicated and there are deadlines to complete them. It is best to consult your bankruptcy attorney in dealing with these issues.