As explained in my previous blog, it is often necessary to run the SSH server inside a GitLab Docker stack on a non-standard port as the default port 22 is reserved for ssh’ing into the server itself. One way to work around that problem is to forward a a non standard port like 1022 on the host machine into the GitLab container’s port 22.
Now how do we handle with such port forwardings on the IDE side?
Cloning a repo from your GitLab server
After you set up a new project on your GitLab server, the project home page shows a Clone button:
Now you have got several options: Among those are generic SSH and http links which you can copy and paste to your command line, plus there are links for cloning the Repo into VS Code directly and which do not work for my machine.
If you connect through a non-standard ssh port, you cannot directly paste the string from the Clone button template into the version control dialogue of your preferred programming IDE. GitLab explains how to amend repo URLs for custom ports in a merge request.
VS Code side
In VS Code, click on the Source Control Icon at the left side of the screen and then click on Clone Repository as shown in the following image:
Then copy the URL string from the Clone with SSH section of your GitLab project. In my case, this is assumed to be
1 |
git@q556.fritz.box:ilek/pybbg.git |
Before pasting this string into the dialogue of your VS Code, you have to made amendment’s for the non-default SSH port as per the instructions given by GitLab. In my case, the amending the link according to the first template provided worked out of the box with GitLab:
1 |
[git@q556.fritz.box:1022]:ilek/pybbg.git |
This is just the URL which you have to paste into the text box which opens upon pressing Clone Repository in VS Code. You will then be asked for a local folder to sync the repo into from the GitLab server.
The generic composition of the SSH repo URL for VS code is:
1 |
[git@SERVERURL:PORTNUMBER]:USER/REPOSLUG.git |
You can also use the above SSH template to clone a git repository directly from the console. Use
git clone [git@q556.fritz.box:1022]:ilek/pybbg.git
.