Verse 2.38 captures the entire essence of the Gita. Krishna tells Arjuna that he would incur no sin when he fights (read as performing any karma ) if he were to treat sukh (pleasure) and dukh (pain); labh (gain) and nasht (losses); and jaya (victory) and apajaya (defeat) with equipoise.
This verse simply says that all our karmas are motivated and this motivation makes the karma impure or sinful. But we hardly know or do any karma without being motivated by pleasure, profit or victory and to avoid pain, loss or defeat.
From Sankhya and Karma Yoga point of view, any karma can be divided into three parts viz. Karta (doer), Chesta (action) and Karmaphal (fruit of action). Krishna divided karmaphal into pleasure/pain, profit/loss and victory/defeat.
Krishna is indicating in this verse to separate these three to achieve equanimity. One way is to drop Kartapan (feeling of doership) and become a sakshi (witness). The realisation is that in the grand drama called life, we play a negligible role. Another way is to realise that we don't have any right over karmaphal (result of action) as it is a combination of many factors apart from our efforts. The paths of dropping of kartapan or karmaphal , are interconnected and progress in one will automatically bring progress in another.
Coming to chesta (action), it was there much before any of us arrived on the planet. It can neither be owned nor can its results be controlled.
This verse can also be approached from the Bhakti Yoga point of view where Bhaav (intent) is everything. Krishna gives Bhaav priority over karma . This internal surrender brings equanimity automatically.
Depending on one's orientation, one can choose their own path. Whatever may be the approach, just by meditating on this verse, one can attain an inner self free of ahankaar.
Source - Daily World