In some cases, strains come from muscle imbalances or weakness, and in other case they can be related to technique. In either case, when you do strain a muscle the following protocol works well:
- Rest. When it is no longer causing a lot of pain, you can start on the rehab.
- Compression and light work. It's better to do a lot of volume with low weight to get fresh blood flowing through the area to help speed healing.
- Slowly increase the intensity until you are back to your previous level of work.
As to preventing it in the first place, it's going to require some coordination with a physio to discern what specifically is going on. I will say that the most common cause of hamstring strains are due to weak hamstrings because they are not regularly exercised. However, the most common cause of pectoral strains is due to technique. That may or may not apply in your specific case.
When exercising or performing sports:
- Warmup is important: if lifting weights, use light weight to get the muscles warm, and increase a little at a time until you get to the work weight. If doing sports, perform controlled bodyweight movements like squats, running in place, etc. that warm up the muscles you will be using.
- Regularly review and correct your technique: Take lots of video and review it. Sometimes you can spot things easily.
- Develop your proprioception (body awareness): If you pay attention, you can catch warning signs before they become something serious. Just as important, you should know how good technique feels.
- Perform helpful assistance exercises: assistance exercises either help you do your main exercises better, or they prevent injury. Typically they are done with lighter weight and higher reps. It's a perfect time to incorporate prehab into your normal routine.
- Work on mobility regularly: mobility work should be done after the main exercise, and can include loosening tight muscles, strengthening weak support muscles, stretching, and foam rolling.
- Exercise regularly: The weekend warrior mentality calls on your body to do things it spent all week forgetting how to do. This is a recipe for injury. Instead training 2-3 times a week for an hour each day spread evenly across all 7 days will be enough to be considered regular exercise.
Building each of these disciplines into your routine will help keep you injury free. If you are coming off a recent injury warmup in the beginning and mobility work at the end becomes much more critical.