That's what I suspected. So essentially, mimic that git command in bash without calling the git command (including the header stuff)?
It is possible in ruby, that's what I used first, though the ref implementation is in ruby, so a single process may not cut it unless you are lucky. Keep trying too if you are solving it but not quite making it in time as you're competing against a variable time to complete on the other side.