Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

preventing git merge to master branch

I am using branching to create and deploy custom instances of out platform. These instances usually start as a branch from the 'master' branch, get customized somewhat, get deployed into testing and production, and finally archived.

If new features or bug fixes are added into the master I would like to be able to fetch/merge them into my project instances (branches), but I almost never want to merge back changes from the branches to the master. This occurred recently by mistake and has created some serious headaches. A git pull to update a repository merged everything into the master branch and then was pushed back into the main repo.

Is there any easy way to forbid merging back into the master? Or at least requiring some --force flag?

like image 562
balm Avatar asked Nov 17 '11 00:11

balm


2 Answers

You can ensure no merging into the master from other branches by forbidding anyone to push the master branch. A person with authority can do that. Gitolite is something that allows you to finely tune access to branches. You can also write your own server side hooks and reject updating of the master branch unless you are a specific user.

like image 178
Adam Dymitruk Avatar answered Oct 02 '22 15:10

Adam Dymitruk


Git is quite happy to work with multiple remote repositories.

I would recommend using one remote repository for each custom instance. This would not change your workflow, as Git can merge any two branches together regardless of origin.

To update a "custom instance" with bug fixes from your "master remote" you'd type something like

git checkout <custom-branch>
git fetch main
git merge main/master

where main is the remote repository you are referring to as master(I changed the name to avoid confusion between a branch and a remote)

For your local branches, do not specify main as the remote tracking branch, instead specify an instance-specific remote. i.e. one remote repository per custom instance.

To push changes to your custom instance, use

git push

In the rare case where you need to push changes upstream to the "master" branch use

git push main
like image 38
Jacob Groundwater Avatar answered Oct 02 '22 15:10

Jacob Groundwater