This is traditionally done by mounting whatever object on a fixed stand and covering it up as best as possible plus some rotoscoping later to erase the stand. Of course one could go all fancy and do it in full CG as well...
There are lots of ways to accomplish this. They all involve pre-production planning. To effectively plan a production you need to know what is required to complete your project.
Required for your scenario:
- A background plate
- A guitar plate
- An actor holding a guitar plate
Now you just have to figure out how to create those plates (layers) and precisely match the position of the guitar.
First option, do as Mylenium suggested, shoot a background plate. Then mount the guitar on a stand, shoot the scene, have the actor walk in and very carefully pick up the guitar, then in post, remove the stand and fill in the background and make an edits between the three shots.
Shoot the background plate, then shoot the Actor holding the guitar but without wrapping his arm around the body or his hand around the neck, then have him position his hand and arm and continue with the action.
In this scenario you would roto the shot of the actor holding the guitar so only the guitar was showing. Then you would simply transition from the background plate to the guitar plate to the plate with the actor and guitar.
With either technique you are just using 3 layers and transitioning from one to another. The project is easiest with a locked down camera. Tracking can be used to match the position of the guitar to the actor holding the guitar. If the camera is moving then here again, you can use tracking and stabilization (not the warp stabilizer) to match up the background, guitar, and actor with the guitar plate.
I hope that gives you some ideas.