Git pre-merge hooks?

For my repository, I am using Git and Stash. At the end of Stash, I restricted access to only the master, so that any user can detach the master branch for the function / branches, but cannot merge to manage directly, unless done with a Pull request.

But as a user, I might accidentally merge my feature branch into the master branch and try to push the master branch.

It's good that pushing is not allowed and is limited by Stash, but I was wondering if there is a way that I could restrict the user to merge any branches with the master locally using some interceptors.

I've tried to intercept hooks and they are great, I was wondering if there was anything similar to it, like pre-join hooks.

+3


source to share


2 answers


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

Ex-Stash developer (not that important).

As @Zeeker pointed out, you need every developer to add hooks to their local repository. And in fact 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 this - local branches have nothing to do with remote branches, except that it's convenient for us to use the same name at the same time. If you need / want to restrict these things, I'll stick with adding bindings to Stash.

+3


source


To do this, you can write a preliminary or preliminary launch. I would prefer a pre-push as you can use a commit to merge the feature branch into master in your local and test integration changes before pull request.



To create a pre-click, you can either ask the developers to create a pre-click binding every time they clone the repository, which is a very repetitive task. Build instead, you can create a pre-push hook in the hooks directory where your git binaries are installed and this will ensure that developers always get hooks no matter how many times they clone or run the repository

-1


source







All Articles