We know Bitcoin has some forks like Bitcoin Cash and Litecoin. They make a new branch on chain, so how can they coexist without the shorter branches being discarded, and just the longest chain staying around? In the Satoshi paper, we read that just the longest chain is valid. So, if each of them has a longest chain, why doesn't one override another, for example assuming Litecoin has longest chain, why are Bitcoin or Bitcoin Cash still working?
For one, Litecoin is not a fork of Bitcoin. It relies on the same base code, but it is a separate network, and they do not share the genesis block.
Bitcoin Cash is a true fork of Bitcoin, in the sense that they can be traced back to the same genesis block.
Both chains continue to exist as they follow different consensus rules. Blocks on the bitcoin Cash chain are considered invalid by the nodes on the Bitcoin chain, and vice-versa. Since they have conflicting consensus rules, they are each the longest valid chains for their own set of the consensus rules.
To include some additional information based on the comments, we can look at why cross communication doesn't happen (in most cases).
For litecoin, the genesis block, network magic bytes (a set of 4 fixed numbers that identify protocol messages for a network), proof of work algorithm, and a number of other things have been different from day one. This would prevent ltc nodes from communicating with btc ones since they would disagree on just about everything.
Things are a little more blurry with Bitcoin Cash. On August 1st, 2017 (almost exactly one year ago!), Bitcoin Cash altered the consensus rules of Bitcoin at that time. They did so by increasing the maximum allowed block size to 8MB, the difficulty adjustment algorithm, and the tx signing method (to prevent replay attacks).
These changes went into affect at block #478558. For all blocks mined after that, Bitcoin and Bitcoin Cash were following different rules. Even if a Bitcoin Cash node was to broadcast a new block to the Bitcoin chain, it would be rejected as:
- It may have exceeded 1 MB
- The transactions were signed in an incompatible way to Bitcoin's signatures
- The difficulty would be vastly lower than the Bitcoin network's difficulty (it was lowered quickly using the new EDA algorithm in Bitcoin Cash). This means that even if the BTC chain received 10 BCH blocks for each BTC block, the total work done would still be higher on the BTC chain since it has a higher difficulty.
Based on the above, Bitcoin nodes would reject the Bitcoin Cash blocks. Moreover, as MCCCS mentioned in the comments, Bitcoin Cash also eventually changed their network bytes, which would prevent a broadcast from accidentally being accepted to begin with, stopping the new block before it even reached consensus validation checks.
Now, lastly, if someone were to manually take the BCH, LTC, Doge, or any other BTC-like chain's data and attempt to broadcast it over Bitcoin's network, they would all still fail various consensus checks.