Social influence aligns peoples opinions, but social identities and related in-group biases interfere with this alignment. For instance, the recent rise of young climate activists (e.g. Fridays for Future or Last Generation) has highlighted the importance of generational identities in the climate change debate. It is unclear how social identities affect the emergence of opinion patterns, such as consensus or disagreement, in a society. Here, we present an agent-based model to explore this question. Agents communicate in a network and form opinions through social influence. The agents have fixed social identities which involve homophily in their interaction preferences and in-group bias in their perception of others. We find that the in-group bias has opposing effects depending on the network topology. The bias impedes consensus in highly random networks by promoting the formation of echo chambers within social identity groups. By contrast, the bias facilitates consensus in highly clustered networks by aligning dispersed in-group agents across the network and, thereby, preventing the formation of isolated echo chambers. Our model uncovers the mechanisms underpinning these opposing effects of the in-group bias and highlights the importance of the communication network topology for shaping opinion dynamics.