The hamstrings are a set of muscles that run along the back of the thigh. They work on both the back of the hip joint and the back of the knee joint.
For convenience I'm going to include the long head of the adductor magnus and the short head of the biceps femoris in the group of muscles called the hamstrings.
The biceps femoris short head attaches to the back of the thigh and from there crosses the back of the knee joint to attach to the fibula.
It can help to flex the knee (or resist knee extension) and it can also externally rotate the shin relative to the femur (or resist external rotation).
The adductor magnus long head attaches, like the rest of the hamstrings bar the biceps femoris short head, to the ischial tuberosity or sitting bone.
It runs down the back of the inside of the thigh to attach to the inside edge of the femur just above the knee joint. So its path is similiar to the two inner hamstrings (semitendinosus and semimembranosus) with the main difference being that it doesn't cross the knee.
Like the hamstrings as whole, the adductor magnus long head can help to flex the hip but more importantly, it helps to internally rotate the thigh. Or another way to think of it is that it neutralizes external rotation of the thigh.
The bottom tendon of the adductor magnus long head, where it attaches to the femur, serves as a foundation for the vastus medialis obliquus muscle. And so an additional function of the adductor magnus long head is to serve as an anchor, when active, for theses fibers of the vastus medialis.
The "actual" hamstring muscles include the biceps femoris long head, the semimembranosus and the semitendinosus.
Of these three muscles, the semimembranosus attaches closest to the capsule of the knee joint.
Semitendinosus attaches, along with sartorius and gracilis, to the inside of the tibia just below the knee joint forming a goose shaped structure called the pes anserinus.
Biceps femoris long head attaches, along with the short head muscle of the same name, to the top of the fibula.
So before going on any further, what do the hamstrings actually do?
At the hip joint they can extend the hip or help to resist flexion. In this regard they can work closely with the gluteus maximus and other hip extensors.
If the hip bone is fixed then generally, extending the hip means moving the leg rearwards. If the femur is fixed, then hip extension means that the hip bone tilts backwards relative to the femur.
In a lunge with one leg forwards and the other back, extension of the back leg hip generally causes the hips to sink down (assuming the back foot remains on the floor.)
At the knee joint the hamstrings can work to bend the knee backwards or to resist is from straightening.
The hamstrings can also be used to rotate the shin bones relative to the femur. This can be more obvious when the knee is bent but may still be detectable, though slight, when the knee is straight. In either case, it can be important to control rotation of the shin whether using the hamstrings or other muscles.
To differentiate shin rotation relative to the femur and shin rotation relative to the foot, I tend to call shin rotation relative to the femur knee rotation
Understanding that the knees can rotate, and that the hamstrings can help control knee rotation can be important when working on improving hamstring flexibility no matter what yoga poses or stretches you are using to stretch the hamstrings.
One reason for referencing the adductor magnus long head and the biceps femoris short head is that both can play a role in controlling knee rotation. Where the adductor magnus long head can help control rotation of the femur at the hip joint, the biceps femoris short head helps control rotation of the lower leg bones relative to the femur.
Read more about knee stability: controlling knee rotation.
Note that another important muscle with regards to controlling knee rotation is the popliteus.
For effective hamstring control it can help to anchor the hamstrings at the top end (at the hip bone) or at the bottom end (via the lower leg bones).
To anchor the hamstrings via the hip bones it can help to create an upwards pull on the sitting bones or PSIC or a downwards pull on the ASIC and/or pubic bone.
Because fibers of the hamstrings are continuous with those of the sacrotuberous ligament, another way of anchoring the top end of the hamstring muscle is to add tension to the sacrotuberous ligament. And one way to add tension to that ligament is to activate the obturator internus muscle.
Note that adding tension to the sacrotuberous ligament is one way of helping to stabilize the SI joint.
Read more about those anatomical elements using the links below:
To anchor the hamstrings via the lower leg bones it can help to utilize the knee extensors (the vastus muscles as the rectus femoris) and/or it can help to stabilize the lower leg bones against rotation. Doing standing poses, this can be accomplished via the foot muscles that act between the lower leg bones and the bones of the foot. Read the article below to find out more about stabilizing the foot via foot exercises that can also be used to fix collapsed arches. (They can also be used to improve balance and proprioception).
For more on stretching the hamstrings check out the following:
For more on strengthening the hamstrings, read this article.
As for an overview of dealing with hamstring problems, check out this article hamstring problems.
Note that the hamstrings as a whole (bar the biceps femoris short head) attach to the ischial tuberosity or sitting bone, a prominent corner point of the hip bone.
For more on the anatomy of the hamstrings, read:
There are a set of hip flexors that attach to the ASIC, another prominent corner point of the hip bone. They also work to help control shin rotation relative to the femur.
Read more about them here:
A muscle that works closely with the hamstrings to extend the hips is the gluteus maximus muscle.
And for more on a muscle that is similiar to the hamstrings but doesn't cross the knee joint read about the adductor magnus longhead here: