One may ask a fundamental question – why do we get attached? Krishna answers this in BG 3.27. While actions (karmāṇi) are being carried out (kriyamāṇāni) completely (sarvaśaḥ) by the modes (guṇaiḥ) of material nature (prakṛteḥ), the spirit soul (ātmā) bewildered by the influence of false ego (ahaṅkāra-vimūḍha) thinks (iti manyate) “I am the doer” (kartāham). (BG 3.27) Because we falsely think we are the sole doers of activities (and the causes of results), which are in actuality being carried out by the modes of material nature – goodness (sattva), passion (rajas), and ignorance (tamas), we become attached to the results. It is almost like being possessed by a ghost while carrying out our actions.
On the other hand (tu), one who is in the knowledge of the Truth (tattva-vit), distinguishing oneself from (vibhāgayoḥ) the mode (guṇa) and the action (karma) does not get attached (na sajjate) knowing that (iti matvā) the modes [influencing the senses] (guṇā) are conducting (vartanta) within the modes [influencing the sense objects within matter] (guṇeṣu) and the actions are being enacted within the modes. (BG 3.28)
Bewildered (sammūḍhāḥ) by the modes (guṇa) of material nature (prakṛter), the ignorant (akṛtsna-vido) entangle (sajjante) themselves in modal action (guṇa-karmasu). But the wise (kṛtsna-vin) should not unsettle (na vicālayet) those ignorant beings (tān), who may be slow in their understanding (mandān). (BG 3.29)
Goodness yields illumination of consciousness, passion engenders hankering and false proprietorship, and ignorance promotes lethargy. Arjuna should fight (yudhyasva) [or carry out his occupational duty] while sacrificing (sannyasya) all (sarvāṇi) actions (karmāṇi) unto Krishna (mayi), with consciousness reposed on the higher self (ādhyātma-cetasā), and being (bhūtvā) free from desires (nirāśīr) and proprietorship (nirmamo), bereft of any lethargy (vigata-jvaraḥ). (BG 3.30) The secret for controlling the senses was revealed in BG 2.61 – engaging all our senses in the service of Lord Krishna (read this section). Lord Krishna, for the second time, gives us a formula for acting in transcendental consciousness (adhyātma-cetasā) by sacrificing all actions for His pleasure (mayi sarvāṇi karmāṇi sannyasya) and thus go beyond the binding effects of the modes and the actions. The emphasis here is not only to engage the fruits of our actions in the service of Krishna but to perform those actions in Krishna consciousness.
It is important to note here that yoga of action (karma-yoga) in its purest form is the yoga of devotion (bhakti-yoga). In the yoga of action, one is detached from the fruits of action while one may be attached to the action itself. In the yoga of devotion, one is detached from the modes and the actions by directing every endeavor for the pleasure of the Supreme.
Krishna is very strong about the consequences of following and not following this particular instruction (enjoined in BG 3.30).
Those (te) persons (mānavāḥ) who (ye) always (nityam) follow (anutiṣṭhanti) this (idaṁ) recommendation (matam) from Krishna (me) faithfully (śraddhāvanto) and without envy (anasūyanto) surely (api) become free (mucyante) from the bondage of action (karmabhiḥ). (BG 3.31) However (tv), those who (ye), out of envy (abhyasūyanto), do not follow (nānutiṣṭhanti) this (etad) instruction (matam) of Krishna (me) know (viddhi) them (tān) to be lost (naṣṭān), unaware (acetasaḥ) and bewildered (vimūḍhāṁs) about all knowledge (sarva-jñāna). (BG 3.32)