Apex cannot talk to Git directly. You'd need to make a callout to a server with the details and have that server perform a commit (and presumably push) against your Git repository.
Part of the Git architecture is that all clients/all repos are equal - the "master" repository is designated by convention, not by design. This means that Git implementations have to implement most or all of Git in order to be functional. Apex doesn't provide large swathes of what would be necessary to actually implement Git, such as a filesystem and sophisticated diffing algorithms.
An alternate design would have an external system call in to Salesforce to source data you've stored in a custom object and check that data into a repository, optionally after transforming it. This would likely be easier to implement; you could build it inside a continuous integration pipeline on any major Git hosting provider.