This is one of the most fearful grammatical points of any japanese learner during their journey to japanese mastery.
This article gives some rules that will help confusion and will make you sound like a native.
Relatively to information intended to be delivered 伝えたい情報
は will always precede the information, whereas が will follow it. Similarily, は will always precede an interrogative, while が will follow it.
これは何ですか。 Here 何ですか is the main information and the interrogative だれがが來ましたか。 Here だれ is the main information and the interrogative
Different role in sentence structure
In complex sentences, は is used after the subject 主語 of the principal clause 主節, while が is used after a dependant clause 従属節 subject.
それはジンが決めたルール。 In this quote from Hunter x Hunter manga, それ is the main subject, while ジン is the subject only for 決めた
Conclusion
I believe が can be thought of as a derivative of が for less important information. That is why は always takes over the main role in the sentence, while が is meant to express dependant informations.
It is good to notice while reading or listening japanese the usage of は and が, to understand intuitively their usage and be able to use them more naturally. They also help ranking the importance of different informations.