Allow force push on all Gitlab respositories

Once I moved all my repos over to gitlab, I realized I needed to make some other unrelated changes to several. I then needed to force push the changes. Because gitlab blocks this by default, and I needed to do this on many repos, I used the following script. First grab a list of repo ids then use those to modify each via the gitlab API.

#!/bin/bash

Get list of ids bellow

curl "https://gitlab.com/api/v4/projects?private_token=<access_token>&simple=true&owned=true&pagination=keyset&per_page=100&order_by=id&sort=desc" | jq .[].id

Use jq .[].name to get the names if needed to match id to name

gitlab_ids=( xxxxxxxx yyyyyyyyy zzzzzzzzz )

for i in "${gitlab_ids[@]}" do

echo &quot;Processing: $i&quot;
curl --request DELETE --header &quot;PRIVATE-TOKEN: &lt;access_token&gt;&quot; &quot;https://gitlab.com/api/v4/projects/$i/protected_branches/master&quot;

curl --request DELETE --header &quot;PRIVATE-TOKEN: &lt;access_token&gt;&quot; &quot;https://gitlab.com/api/v4/projects/$i/protected_branches/main&quot;

curl --request POST --header &quot;PRIVATE-TOKEN: &lt;access_token&gt;&quot; &quot;https://gitlab.com/api/v4/projects/$i/protected_branches?name=*&amp;allow_force_push=true&quot;

sleep 0.2

done

© 2024 Code0x378