I have a Git repository. This repository has multiple remote repositories (I think). How can I get a list of the remote repositories that belong to said repository?
Like git list --remotes
or something like that?
I have a Git repository. This repository has multiple remote repositories (I think). How can I get a list of the remote repositories that belong to said repository?
Like git list --remotes
or something like that?
You can get a list of any configured remote URLs with the command git remote -v
.
This will give you something like the following:
base /home/***/htdocs/base (fetch)
base /home/***/htdocs/base (push)
origin git@bitbucket.org:*** (fetch)
origin git@bitbucket.org:*** (push)
git remote -v
because -v is for verbose. git remote
gives a simple list of remotes (base, origin in this case). The -v option includes the url for both fetch and push operations of each remote.
-v
for "verbose" is actually the more common option. It's also supported by git branch
. The basic difference is short vs long options (single vs double dash, essentially) That said, supporting --list with the remote
subcommand would make sense. If you really want it, I'd say submit a feature request.
git remote -v
If you only need the names of the remote repositories (and not any of the other data), a simple git remote
is enough.
$ git remote
iqandreas
octopress
origin
The answers so far tell you how to find existing branches:
git branch -r
Or repositories for the same project [see note below]:
git remote -v
There is another case. You might want to know about other project repositories hosted on the same server.
To discover that information, I use SSH or PuTTY to log into to host and ls
to find the directories containing the other repositories. For example, if I cloned a repository by typing:
git clone ssh://git.mycompany.com/git/ABCProject
and want to know what else is available, I log into git.mycompany.com via SSH or PuTTY and type:
ls /git
assuming ls
says:
ABCProject DEFProject
I can use the command
git clone ssh://git.mycompany.com/git/DEFProject
to gain access to the other project.
NOTE: Usually
git remote
simply tells me aboutorigin
-- the repository from which I cloned the project.git remote
would be handy if you were collaborating with two or more people working on the same project and accessing each other's repositories directly rather than passing everything through origin.
ls
on /git and cloning random repo's as desired is typically not a healthy usage scenario, seems. like a serious misconfiguration of both the git repo and the server hosting it. This does not work in corporate environments, ( or smaller shops with minimal security practices in place ).
Oct 22, 2021 at 1:46
FWIW, I had exactly the same question, but I could not find the answer here. It's probably not portable, but at least for gitolite, I can run the following to get what I want:
$ ssh git@git.xxx.com info
hello akim, this is gitolite 2.3-1 (Debian) running on git 1.7.10.4
the gitolite config gives you the following access:
R W android
R W bistro
R W checkpn
...
A simple way to see remote branches is:
git branch -r
To see local branches:
git branch -l
git ls-remote
should show you all the remotes available for fetching from the upstream server (git-scm.com/docs/git-ls-remote). I believe that all the answers on this page only tell you how to list the remotes and tracking branches that you have already fetched, which is a Catch-22. You can't fetch a remote until you know how to refer to it on the upstream server.
Oct 27, 2016 at 0:07
None of those methods work the way the questioner is asking for and which I've often had a need for as well. eg:
$ git remote
fatal: Not a git repository (or any of the parent directories): .git
$ git remote user@bserver
fatal: Not a git repository (or any of the parent directories): .git
$ git remote user@server:/home/user
fatal: Not a git repository (or any of the parent directories): .git
$ git ls-remote
fatal: No remote configured to list refs from.
$ git ls-remote user@server:/home/user
fatal: '/home/user' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
The whole point of doing this is that you do not have any information except the remote user and server and want to find out what you have access to.
The majority of the answers assume you are querying from within a git working set. The questioner is assuming you are not.
As a practical example, assume there was a repository foo.git on the server. Someone in their wisdom decides they need to change it to foo2.git. It would really be nice to do a list of a git directory on the server. And yes, I see the problems for git. It would still be nice to have though.