Shorten Git SSH URL
30 Dec 2021 - Tyler
I set up my VPS to act as a remote Git repository so that I can store things on there as well as on GitHub. In doing so I realised though that the URL can get a bit unruly. When I wanted to add a remote to one of my local repositories I had to use:
Its not so bad, but of course we are lazy efficient. Wouldn’t it be nice if instead of ssh://user@10.10.10.10:8910/path/to/your/git/repo.git
you could just use yourserver://repo.git
? Of course like most things in the developer world this is possible, I’ll show you how.
All we need to do is open up your .gitconfig
and add a couple lines.
Of course, in this example replace:
user | : your username |
10.10.10.10 | : your server ip (or domain name if its configured) |
8910 | : your ssh port (which definitly isn’t 22 right?) |
/path/to/your/git | : the path to where your git repositories sit on your server |
yourserver:// | : whatever you want to use as a shortened url |
Alternatively you can use the git
cmd to do it as well:
Now, after you’ve added the blank git repository on your server, all you need to do from the project root is:
Quite a bit easier, eh?