How often does temporary fork occur and how long does it last? I was wondering, how often does temporary forks occur? They appear when there are two different blocks mined based on the same previous block (parent block), but what are chances for that? And if fork occurs, how long does it last (on average)? What is the moment in a chain when side branch gets discarded by the network, or when is the node certain that the branch he continues to mine on is really the longest one (following the longest chain rule)? 
Thank you guys!!
Blockchain forks occur when two blocks are found at the same height. Only one of the two chaintips can become part of the best chain. Each full node will consider the first block it saw to be the best block for that height, until proven otherwise by another chaintip accumulating a greater total difficulty (i.e. adding another block). When another chaintip pulls ahead, the node will reorganize to the best chain. The node reverts its current chaintip back to the last shared block and then applies the blocks from the best chain. A blockchain fork is generally resolved whenever a block for the next height is found. The &quot;best chain tip&quot; is always a probabilistic determination, but the confidence quickly rises as more blocks get added (hence the recommendation in the white paper to wait for six confirmations). Nothing prevents a miner to continue mining on a stale chaintip. However, a miner cannot spend the block reward if the block does not become part of the best chain, so in most cases, it is unreasonable to mine on a stale chaintip. A miner with a large portion of the hashrate may try to extend a stale chaintip if they authored the stale block in a selfish-mining attack.
Earlier in Bitcoin's history there were some two dozen cases in which blockchain forks consisted of multiple blocks before a best chain emerged. You can read more about that in What is the longest blockchain fork that has been orphaned to date?. As far as I'm aware, we have not had a multi-block chainfork for multiple years.
If you have access to a Bitcoin Core instance that has been running for a long time, you can get all stale blocks it registered by calling the getchaintips rpc. Obviously, your node might not have seen all stale blocks that have occurred. Any node syncing later, will only download the best chain, and not acquire these stale chain tips.
Stale blocks were a fairly common occurrence in 2013-2015. IIRC, there would usually be one or more per day.
Headers-first sync introduced with Bitcoin Core 0.10.0 significantly reduced that. In 2016 the Fast Internet Bitcoin Relay Engine (fibre) replaced a previous effort (the &quot;Bitcoin Relay Network&quot;) to provide a supplementary relay network connecting especially mining entities that directly pushed new blocks to other participants.
The rate of stale blocks further dropped around the time that segwit got activated. Some people surmised back then that some miners had been running old versions of Bitcoin Core, and when segwit activation forced them to update to a segwit-compatible client, they leapfrogged a number of block relay improvements that had been added over the years. Another rumor was that some mining outlets (spending millions on mining hardware!) used micro-computers as their mining controllers which would take a while to validate new blocks, delaying their switch to the latest chaintip.
These days, it's common that the network goes weeks without any stale blocks. BitMEX Research runs a forkmonitor which offers an RSS feed to alert users when stale blocks (and other block related events) occur. Unfortunately, it seems to me that the RSS feeds item list was reset and I was unable to find a list of their history of fork alerts. In lieu of that, let me note that BitMEX Research tweeted on 2020-01-26 that they had seen a stale block at height 614,732 and that this was the first stale block they had registered since 2019-10-16. Searching BitMEX Research's tweets for &quot;stale&quot;, since 2020-01-26, they also tweeted about stale blocks on 2020-07-10, 2020-06-09, 2020-03-03, 2020-02-27, and 2020-02-22. Assuming BitMEX research tweeted about each, they have recorded seven stale blocks since 2019-10-16.
Note that the &quot;orphan block chart&quot; provided by blockchain.com appears to be broken.