In storyline terms, the gangs are composed of Exiles who sought to carve out a place for themselves in the Matrix whether for protection, profit or to advocate an ideal.
Most of them are led by one of the "mission contacts" who can be found around the Mega City eg Indigo of the King's Men in Guinness Lake in Westview, or Mr.Black of Corporate Security, both in Stratford Campus of Downtown.
Once your neurokinetic (character's) level has gone above that of the gang NPCs, they no longer attack unless provoked, such as attacking a gang member in full view of others of the same gang.
Presently, there is no way to completely remove an Exile gang's presence from the Matrix, though there are opportunities where you can choose to help or hinder their operations, such as in certain Live Events.