Usually, torsocks is recommended to access git repositories over tor.

This is incompatible with my current workflow, which includes an foreach-like interation over all repositories to fetch their remote refs. Looking for ways to make an default git fetch use tor per default, i opted to create a custom remote helper. You can read about the mechanism in general in gitremote-helpers(1).

To trigger the helper, i prefix every remote i want to access via tor with tor://. The helper then checks the rest of the url and delegates the work to the torsock-ed original remote helper. This way i can use git fetch generically without bothering on the actual transport mechanism.

I’ll quote the PoC version of the helper here. The full version can be found in my scripts repo:

exec torsocks git-remote-http "$1" "$url"