get list of all project branches via api/command line

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
go something like git ls-branches 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

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:


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:

curl -H "Authorization: token $TOKEN"

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: 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).



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.
    	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.

Hi @andreagriffiths11 

I have successfully recieved reponse from the github branches api.

However, the response did’nt contain all the branches in my repo but 10 of 100.

How could I get all my branches info?

Looking forward to hearing from you.

1 Like

This is super accurate solution to the problem (for CLI).