1

I want to be able to get all branches from a project that are protected. The protection is done in gitlab, so I wasn't sure if there's API exposed so I can get it from the command line.

I looked at git branch command, but I didn't see anything there that could tell me whether a branch is protected or not.

jsirr13
  • 884
  • 2
  • 12
  • 37
  • 3
    "Protected" is a property of one of those web interfaces (gitlab in this case), not of Git itself, so you're right: `git branch` *can't* tell you. (Also, in your own Git repo, everything is, well, your own.) – torek Feb 28 '18 at 00:55
  • Is there anyway I can tag certain branches, or some alternative approach so that I can distinguish from certain remote branches vs others? – jsirr13 Feb 28 '18 at 00:57
  • There's no way to automate this within Git (since Git has no idea that the remote has arbitrary constraints), but if you find some API you can run, you can automate whatever you like and make it do whatever you want. But there's no reason to change the way you work with your own Git locally anyway, as there's no constraint that your own Git branch's names match your Git's `origin/*` remote-tracking names. – torek Feb 28 '18 at 01:01

1 Answers1

2

You can use the GitLab API for listing protected branches.

GET /projects/:id/protected_branches

From there, you can use in your local repo git config or git notes to leave a "marker" to your branches.

VonC
  • 1,129,465
  • 480
  • 4,036
  • 4,755