27

In order to clone a git repository one must have the name of the repository. When working with many repositories it can be hard to remember all the different names, so now I'm wondering if there is possible to list all existing repositories on the remote server using some git command.

8

You'd either need Shell access to the machine hosting the git-daemon and see the params used to invoke git-daemon or use the Git Web frontend (Repository browser) called GitWeb.

Also refer this existing question

There is one other way but it needs some assistance of you companies server admins. Git features a browsable web frontend called 'GitWeb' which can be configured to show all projects served by git.

Details are explained in the GitWeb README - the config key of interest is called "GITWEB_PROJECTROOT":

GITWEB_PROJECTROOT The root directory for all projects shown by gitweb. Must be set correctly for gitweb to find repositories to display. See also "Gitweb repositories" in the INSTALL file for gitweb.

Maybe you could have a talk with you admins - gitweb can be a great profit for all developers.

As far as I can tell, this needs to be done on the machine that is running git-daemon. You either need to check the arguments where git-daemon was invoked, or possibly check /etc/inetd.conf

| improve this answer | |
1

This is heavily dependent on how those repositories are accessed, so there isn't really a simple one-size-fits-all answer:

  • If the repos are being served by git-daemon and/or gitweb, you can look at the config to see where it keeps its repos and list the contents of that directory.
  • If the repos are accessed via ssh, then they can be located anywhere in the filesystem. You should be able to find them by looking for all directories on the system containing a file named HEAD (e.g. locate HEAD | grep \/HEAD$), but this may produce false positives and it will also show any repos which are solely local working directories and are not shared or were cloned from another source.
  • If the repos are managed by gitlab, they're not in the filesystem at all, so you need to use the gitlab web interface to list them. Note that some repos may be hidden from this list if you don't have permission to access them.
| improve this answer | |
0

Since I had shell access to the remote machine I ended up writing a small fabric script that could be run from the terminal to list all remote repositories:

#!/bin/python

from fabric.api import run, env
from fabric.colors import green 

env.hosts = ['<hostname>'];
env.user = '<user>';
env.password = '<password>';

def lr():
  "Lists all remote repositories"
  print(green("listing remote repos"))
  run('cd /var/git; ls -al')

I can now list all remote repositores by issuing the following command from the terminal:

fab lr
| improve this answer | |
  • 1
    Note that this script assumes the git repositories are located in /var/git. While this is commonly the case, it's not always true. – Dave Sherohman Dec 19 '18 at 10:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.