Any way to distinguish branch name part from file pat within a url?

Here is my case:

The input is a URL “Shows a file” (from


I want to distinguish the actual file path part from a branch name. So, ‘master’ from ‘STL%20files/Electronics%20box/Box.STL’ in this case.

The problem is that branch name can have slashes in it. Example:

In this case, branch name is ‘custom/branch’ and path is demo.gif

The resulting path/branch is going to be used in an API call:


Where ‘:path’ just a file path only, and branch name is provided via ‘ref’ parameter.

The way we do it right now is by iteratively removing parts from everything after ‘blob/’ (in the incoming URL) waiting for non-404 response. This feels wasteful. If someone has a branch name with many slashes - we will make many useless calls.

Is there a way?

It’s been solid 3 months since I asked that. Not sure if bumping old unanswered question is ok here, but here I go