How were Italian townsmen were able to set up independent communes?

How were Italian townsmen were able to set up independent communes?