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?
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With