This function recursively inserts the given object and any referenced ones. It can be thought of as a more general version of the functions to insert a commit or tree.