'How to Git control code from a remote computer?

I have the following situation:

  1. I have a remote workstation (WS_A) in which I have code written. I write and execute the code in this workstation
  2. I access WS_A through SSH from my local Linux computer (loc_m). I also use Visual Studio code remote extension to directly code the code in the workstation. I transfer files from and to the WS_A using scp
  3. The worskation WS_A does not have access to the internet.

So I would like to do the following:

  1. Git manage my code: Simple enough, Git is installed in the workstation so no problem
  2. Keep a repository of this code in my local machine loc_m
  3. Keep a repository of this code in GitLab (or GitHub alternatively)

How can I do 2 and 3?



Solution 1:[1]

The worskation WS_A does not have access to the internet.

But you have SSH access to it, which means it does have access to the internet, ...provided you set up a reverse SSH tunnel.

  • If loc_m is Windows, install px in order to set your HTTP(S)_PROXY to localhost:3128
  • if loc_m is Linux, install a proxy like squid, again to set an HTTP_PROXY to localhost:3128.

Then, from loc_m:

ssh -R 3120:127.0.0.1:3128 -fNT -o IdentitiesOnly=yes -o PreferredAuthentications=publickey WS_A

With WS_A an entry in your ~/.ssh/config file:

Host WS_A
  hostname ws.A.hostname
  User rmeoteUser
  IdentityFile ~/.ssh/key_for_WS_A

On WS_A, set HTTP_PROXY/HTTPS_PROXY to localhost:3120: that port will be redirected to your local machine, port 3128, which in turn has internet access.

From there, your remote code can be directly committed and pushed to GitHub/GitLab. No more scp back and forth.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1