How to force push to Gitlab

From the official documentation on dealing with Protected Branches:

  1. Navigate to your project’s Settings ➔ Repository
  2. Scroll to find the Protected branches section.
  3. From the Branch dropdown menu, select the branch you want to protect and click Protect.

Following the steps above, you should be greeted with a box similar to this one below.

Two configuration sections. One to set configurations and another that lists which branches on your GitLab repository are protected

There, you can click either:

  • “Allowed to force push” toggle button, or
  • the orange Unprotect button

for the branch you want to force push to, e.g., master.

If you don’t want to navigate through the navigation bars, you can also fill out this URL template:

https://gitlab.com/<USERNAME>/<PROJECTNAME>/settings/repository#js-protected-branches-settings

and replace <USERNAME> and <PROJECTNAME> with your specific username and project name, respectively.

Note, the “Allowed to force push” button is probably favored over un-selecting the Unprotect button because branch protection gives you additional safety from accidentally deleting your branch. But either option appears to work.

More help:

  • Community discussion on force pushing on branch https://gitlab.com/gitlab-com/support-forum/issues/93
  • Official documentation to do so https://docs.gitlab.com/ee/user/project/protected_branches.html

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)