You would have some sort of nano-machine select a cell, observe how it is connected to other cells, destroy that cell, and take its place, restoring the connections identically. It would also have to be able to form new connections and change existing ones, just like real brain cells. You introduce new nano-machines gradually over some amount of time. The machines could even create more of themselves, repair themselves, expand the brain, etc. Of course, all this would be complicated and beyond our current technology.