Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git pre-merge hooks?

For my repository, I am using Git and Stash. On the Stash end, I have restricted (read only) access to master, so that any user can branch off the master branch for feature/ branches but cannot merge to master directly unless its done via a Pull request.

But as a user, I can accidentally merge my feature branch to the master branch and attempt to push the master branch.

The good thing is that, the push isn't allowed and is restricted by Stash, but I was wondering if there was a way I could restrict the user to merge any branches to the master locally with the help of some hooks.

I was trying out pre-commit hooks, and they are great, I was wondering if there was something similar to it, such as pre-merge hooks.

like image 307
Dexter Avatar asked Nov 01 '22 12:11

Dexter


1 Answers

I was wondering if there was a way I could restrict the user to merge any branches to the master locally with the help of some hooks.

Ex-Stash developer (not that it matters).

As @Zeeker mentioned you need to have each developer add hooks to their local repository. And in facts it's worse than that. Let's say you do the following:

git checkout -b this-is-not-master
...
git commit -m "This is not on master"

But then you do this:

git push origin this-is-not-master:master

At what point was the user "on" master? Basically you can't do it - local branches have nothing to do with remote branches, except that it's convenient for us to share the same name sometimes. If you need/want to restrict these things I would stick to adding hooks to Stash.

like image 149
charleso Avatar answered Nov 15 '22 05:11

charleso