Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Copilot Lvl 2
Message 1 of 3

get list of all project branches via api/command line

Solved! Go to Solution.

I'm trying to figure out how I can get a list of remote branches without creating a local repository. For example.

I want to pull a list of all branches at https://github.com/joomla/joomla-cms.git
go something like git ls-branches https://github.com/joomla/joomla-cms.git would be ideal.

I will be doing this via either CLI or php dependening on which one will work.

either way each time the script is call the url could be different.

Thanks in advance

2 Replies
Solution
Community Manager
Message 2 of 3

Re: get list of all project branches via api/command line

Hi @N6REJ,

 

Thanks for being here! I'm sharing the solution you've received from Support here as it might help others. 

 

There are a few ways that you can do this. I'd recommend from the terminal, and using v3 of our API (REST) you can make a GET request to fetch these specifically (as documented here: https://developer.github.com/v3/repos/branches/#list-branches)

 

curl https://api.github.com/repos/joomla/joomla-cms/branches

 

Or if this is a private repository that you have access to then you'll need to make an authenticated request using either an OAuth / Personal Access Token or using basic authentications (username / password) (as documented here:https://developer.github.com/v3/#authentication):

 

curl  -H "Authorization: token $TOKEN"  https://api.github.com/repos/joomla/joomla-cms/branches

 

In the above request you'd substitute the placeholder $TOKEN with your access token.

 

If you'd like to achieve this via PHP there are a number of libraries that wrap around this API, for instance: https://github.com/KnpLabs/php-github-api however this is a third party API so we cannot support issues with the libraries implementation directly (you'll have to raise an issue on the repository itself).

 

Mark helpful posts with Accept as Solution to help other users locate important info. Don't forget to give Kudos for great content!

Copilot Lvl 2
Message 3 of 3

Re: get list of all project branches via api/command line

TY!

I did stumble upon a way that hopefully is ok with staff.

for /f "tokens=3* delims=/" %%f in ('call git ls-remote --heads %repo%') do (

REM check to be sure we got a list of branches back.
	IF ERRORLEVEL 1 (
    	ECHO Sorry we couldn't find any branches in the %repo%
    	EXIT /B
	) ELSE (

	REM yep, we did so lets populate the array of branches.
	set /a "count=count+=1"

	REM Populate array
	set branch[!count!]=%%f

	)
)


I literally searched for days to figure SOMETHING out.  I really appreciate your help.