Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

List remote branches without cloning the repo ? #81

Answered by janpecha
ahmed-bhs asked this question in Q&A
Discussion options

Hello, is there a way to get the getRemoteBranches from a remote repo without cloning it locally?

 $git = new \CzProject\GitPhp\Git;
 $repo = $git->open('https://github.com/czproject/git-php.git');
 var_dump($repo->getRemoteBranches());

But this return :

 "Repository 'https://github.com/czproject/git-php.git' not found.",
 "file": "/var/www/vendor/czproject/git-php/src/GitRepository.php",
 "line": 28,

Any help would be appreciated!

You must be logged in to vote

Hello!

I see two options:

1) Use empty local repository

$git = new CzProject\GitPhp\Git;
$repo = $git->init(__DIR__ . '/empty-repo');
$repo->addRemote('origin', 'https://github.com/czproject/git-php');
var_dump($repo->execute('ls-remote', '--heads', 'origin'));

2) Use CliRunner directly and run command ls-remote manually

$runner = new CzProject\GitPhp\Runners\CliRunner;
var_dump($runner->run(__DIR__, ['ls-remote', '--heads', 'https://github.com/czproject/git-php'])->getOutput());

Replies: 1 comment 2 replies

Comment options

Hello!

I see two options:

1) Use empty local repository

$git = new CzProject\GitPhp\Git;
$repo = $git->init(__DIR__ . '/empty-repo');
$repo->addRemote('origin', 'https://github.com/czproject/git-php');
var_dump($repo->execute('ls-remote', '--heads', 'origin'));

2) Use CliRunner directly and run command ls-remote manually

$runner = new CzProject\GitPhp\Runners\CliRunner;
var_dump($runner->run(__DIR__, ['ls-remote', '--heads', 'https://github.com/czproject/git-php'])->getOutput());
You must be logged in to vote
2 replies
Comment options

@janpecha thank you for your answer, really appreciate your help.
Any idea why when I change the remote to ssh like this :

$runner = new CzProject\GitPhp\Runners\CliRunner;
var_dump($runner->run(__DIR__, ['ls-remote', '--heads', ' "git@github.com:czproject/git-php.git"])->getOutput());

I got this error message"Host key verification failed. fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.", ! Cheers!

Comment options

I don't know why, if I changed repository address, it worked too:

$runner = new CzProject\GitPhp\Runners\CliRunner;
var_dump($runner->run(__DIR__, ['ls-remote', '--heads', "git@github.com:nette/utils.git"]));
Answer selected by ahmed-bhs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /