How to force push to GitLab (but don't do it, please)

1 min. read

Caution! This article is 8 years old. It may be obsolete or show old techniques. It may also still be relevant, and you may find it useful! So it has been marked as deprecated, just in case.

This post should start with a big red warning:

Never force push to master, evah! Or you will piss off a lot of people, specially all the other people working with you in the same project. And then, all the kittens of the world will die at once.

-- Me.

Now, after you tattoo this quote in a visible part of your body: if you are using the awesome and REALLY open-source git repository known as GitLab, then, you will still not be able to force push to master.

Why? Because GitLab has just created "protected branches", a concept to protect you from yourself, and that will save us from many headaches in the future, in my humble opinion.

So, if you want to force push to GitLab from now on, you will have to:

  • Log in to GitLab
  • Go to your repo.
  • Click "Settings".
  • Click "Protected branches".
  • Find the branch you want to force push to and click "Unprotect", just next to it.
  • Force push.
  • Go back to the Protected branches page and in the "Branch" dropdown, select your branch again.
  • Click "Protect".

With knowledge comes responsibility, so use this information wisely :-)