In the case of most indices, the rebalancing happens quarterly or half-yearly. During the rebalancing, certain stock(s) may be excluded, and in its place other stock(s) may be included. Whenever that happens, the index fund manager sells the stock(s) excluded from the index. In its place, the fund manager buys the new stock(s) included. The shares bought are as per the weightage of the new stock(s) in the index.