How does green screening work with green objects?
For static shots they shoot what's called a background plate: the same scene shot from the same angle but without the foreground action. Then where the green is taken out the empty background shows through.

If the camera is moving this presents a problem. This can be solved by using motion control - basically a robot arm with the camera on it that can repeat the same camera movement with and without the foreground action. This technique is being used less and less, because today even a modest laptop running off-the-shelf software is now capable of tracking moving cameras in 3D. So that the computer works out where the camera was in 3D space, then the background–which can be real or CGI–can be composited with the camera footage.