I have set up gits in the past, and have used Tor to protect them. It works just as setting up any other service. Simply set up your server (ensure that there is not something that could expose your true IP address in it), and then forward the port to Tor.
The only problem I have had in the past with this is the fact that it isn't easy to connect to Tor ...
While marked answer is 100% correct I use a bit different approach. For ssh connections using OpenSSH client I utilze ProxyCommand for *.onion sites in the following way:
ProxyCommand socat STDIO SOCKS4A:<tor socks hostname or IP>:%h:%p,socksport=9050
This should also be the only change needed for git ssh ...
torsocks is the way to go. You may need to install it separately from Tor if it is not installed automatically.
Make sure Tor is running: systemctl status tor
Run your command through torsocks: torsock git pull or torsocks ssh abcxyz.onion
Another option is to run torsocks --shell. This will make all commands in that shell automatically run through Tor. ...
From the Tor manual site:
Add the following lines to your torrc:
HiddenServicePort 80 127.0.0.1:8080
You're going to want to change the HiddenServiceDir line, so it points to an actual directory that is readable/writeable by the user that will be running Tor. The above line should work if ...