Export library as git repo or similar to keep history info

Is there a way to export libraries along with their commits into a git format or similar?