Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git repository URL - SSH syntax without absolute path

Tags:

git

ssh

I'm running a git repository server accessible via SSH, on a custom port (let's say 12345). I have found that in this case the repository URLs need to be specified using SSH syntax:

git clone ssh://[email protected]:12345/absolute/path/to/repository 

I'd like to setup it in such a way that it would be possible for users to clone repositories without specifying the absolute path.

git clone ssh://[email protected]:12345/repository.git 

I have researched the topic and found the following options:

  1. Remove the custom port from the URL and make the users add it to their ~/.ssh/config file (a last-resort workaround rather than a solution).
  2. Drop SSH and use git-daemon and specify its --base-path parameter (still a workaround...)
  3. Use an utility like gitosis or gitolite - but wouldn't it be an overkill to use it for this purpose only? Gitosis is discontinued, gitolite is a quite huge piece of software...

All I want is a "prettier" SSH URL with custom port (so I can distribute the whole git clone command and require nothing more from the remote user). Which one of the above solutions would be the most viable in my case?

like image 538
Neo Avatar asked Jan 15 '13 23:01

Neo


People also ask

What is Git SSH URL?

SSH URLs provide access to a Git repository via SSH, a secure protocol. To use these URLs, you must generate an SSH keypair on your computer and add the public key to your account on GitHub.com.

Where is SSH URL in GitHub?

To find the GitHub SSH URL for a given repo, go to the repository's landing page and click on the green Code button. This presents three separate options to connect to Git: a GitHub SSH URL; a GitHub HTTPS URL; and.


2 Answers

If you use the alternate form of ssh URLs you don't need an absolute path. For example...

git clone [email protected]:repos/myrepo.git 

...will clone repository repos/myrepo.git relative to my home directory, although this doesn't permit use of an alternate port. However, you can also use ~ in either form to indicate the user's home directory, e.g.:

git clone ssh://[email protected]:12345/~/repository.git 

Incidentally, despite being discontinued, gitosis functions quite well, and the code is both small and easy to understand. It offers a useful set of access controls and self-service management of repositories. I wouldn't discount it completely.

like image 79
larsks Avatar answered Oct 13 '22 00:10

larsks


I do this, not exactly what you asked, but close and with prettier links:

create a path like

/srv/git  

where you place you git projects

next make a symbolic link to home:

ln -s /srv/git $HOME 

next you can have shorter links

git clone user@server:git/myproject.git 

if you have a single project you can get rid of the git/ part in the url

ln -s /srv/git/myproject.git $HOME 

next

git clone user@server:myproject.git 

will work. Of course the .git at the end of the URL comes only from creating the bare with .git in the name. Note also that ssh:// part is not needed: the @ implies it is an ssh URL for git.

Updated: let me add a sidenote: following the most recent Filesystem Hierarchy Standard I use now /srv/git as repository location.

like image 22
user1708042 Avatar answered Oct 12 '22 23:10

user1708042