2

I would like to prevent execute a push on GitLab if someone before pushed an other commit. I would force him to pull first, then do an interactive rebase. I thought I need server side git hook.

I red tis article: https://docs.gitlab.com/ce/administration/server_hooks.html

but I stuck on this line: On the GitLab server, navigate to the project’s repository directory.

How can I log into GitLab? I installed gitlab-runner but I have no clue how to "Log In` and add the pre-receive script to the hooks subdirectory.

Do you have any idea?

János
  • 32,867
  • 38
  • 193
  • 353

1 Answers1

1

Protecting the branch should be enough: that would prevent from force pushing to the branch.
And it can be set through GitLab GUI, without having to log on to the GitLab server.

That means: if someone already pushed, you will have to pull first, before being able to push yourself.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Hi! I protected the branch, but it does not prevent to push it :( – János Apr 27 '20 at 12:33
  • @János it prevents "`git push --force`", which is enough: the only way to push "if someone before pushed an other commit" is to force push. Since the branch is protected, you won't be able to push (even with a force), you will have to pull first. If you *can* push, that means nobody has pushed a commit before your push. – VonC Apr 27 '20 at 12:49
  • Ahh, I see, would you check this as it belongs to here: https://stackoverflow.com/questions/61460843/is-it-a-way-to-avoid-branch-out-branch-in-when-git-pull – János Apr 27 '20 at 14:12
  • @János Sure. I have put an answer there. – VonC Apr 27 '20 at 16:02