Alright, so far in my four playthroughs (one for each faction), I've always had to destroy another faction such as The Railroad for The Institute and vise versa. Is there any way to avoid this?
Under normal circumstances, no, one or more factions will die.
However, there is a comprehensive guide on how to beat the game with no non-Institute factions killed, but it is not recommended because it is convoluted, you play the story missions in a very specific and sometimes unnatural order, and it makes the story really confusing.
It is best to beat the game once, then follow the guide if you ever want a save with everyone alive.
Long guide follows, along with obviously massive spoilers:
Step 1: Before completing "Reunions," complete all main and both side quests (once each) for the Brotherhood of Steel recon team. Talk Brandis down from being crazy.
Step 2: Complete "Reunions" and "Dangerous Minds." (For proper completion, keep Preston at the Castle.)
Step 3: (a) You will have received "Tradecraft" and "Shadow of Steel." DO NOT advance in either of these quests. (b) Focus on the Minutemen as you continue down the main quest line. Use the Minutemen to gain access to the Institute. © Get yourself banished from the Institute. You can play along and poke around for a bit first if you like, but if you do, you'll have to murder someone to get banished (might we suggest those ♥♥♥♥♥♥♥s down in synth retention?). You may safely complete "Institutionalized," but do not progress any farther before getting yourself kicked out. Don't even speak to Father again after completing "Institutionalized." DO NOT complete "Synth Retention." (Give holotape to Sturges.)
Step 4: (a) You will have received "Form Ranks" for the Minutemen. DO NOT advance this quest. (b) DO NOT start "Defend the Castle." Don't even go to the Castle. © Complete all quests for the Brotherhood from "Shadow of Steel" to "Show No Mercy." DO NOT complete "Show No Mercy." Don't even get on the Vertibird. Grab ALL side quests from the Brotherhood and keep them open.
Step 5: Complete "Form Ranks" and "Defend the Castle." Start "The Nuclear Option" for the Minutemen but DO NOT complete it.
Step 6: Complete all Railroad quests from "Tradecraft" to "Randolph Safehouse 6."
Step 7: Complete "The Nuclear Option."
That's it! This process will result in all factions loving you. The heads of the Brotherhood will praise your actions (except Max, who is pouting and won't talk to you). From here on out, they will not start fights and will only kill mutants and raiders. Many of their quests and side quests are repeatable. The Railroad has a whole new line of quests for you, and there is fun to be had everywhere (however, don't talk to P.A.M. after this; she wants to start a war with the Brotherhood). Enjoy your (relatively) peace-filled Commonwealth!
(BTW, if one of your companions is being attacked by another faction, this is most likely because they got hit with some crossfire while in a multi-faction battle and then shot back. This happens often...and is annoying as hell. Danse will shoot down his own Vertibird then leave you because he is mad that you shot down his friends. Yeah.)
Once again this route offers all companions but 1. All factions will be at peace will all other factions and no companions will be hostile to any of them.
From the end of this article:
...no matter what you do, two factions will be destroyed, locking their quests forever.
This is because:
Each of the Act Three questlines involves destroying two factions, and once you’ve knocked off the first one you have one last chance to switch sides, either by betraying the Brotherhood to the Institute or vice versa.
In short, no. You can't avoid this. You have to take out two factions actually. Here is who you destroy if you side with a particular faction (read at your own risk!):
Brotherhood of Steel and The Institute
Brotherhood of Steel:
The Institute and The Railroad
Brotherhood of Steel and The Institute
Brotherhood of Steel and The Railroad
Whatever faction you don't destroy for each particular faction you side with, you can also ally with.