Prevent pushing to master on GitHub?
Since the original question / answer, Github has added a new option for this to the restricted branches UI which allows you to set this up.
Require pull request reviews before merging When enabled, all commits must be made to a non-protected branch and submitted via a
pull request with the required number of approving reviews and no
changes requested before it can be merged into a branch that matches
this rule.
To find it go to Settings > Branches > Branch Protection Rules
and click 'Add Rule'.
Then, enter the name of the branch you want to protect and click the checkbox to require pull request reviews before merging.
By default, this only stops people who are not moderators. There is also another checkbox later down for ensuring that even moderators cannot merge.
How to block/restrict push to remote master totally
See the docs on pre-push hooks, and the .git/hooks/pre-push.sample
given with any repo :
information on the target references is passed through stdin, not through sys.argv
How to block push to master branch on remote
The original script was perfect, I just needed to rename it from .git/hooks/update.sample
to .git/hooks/update
on the remote server and make sure it's executable.
#!/bin/sh
if [ $USER != "git-repo-admin" ];
then
if [ "$1" == refs/heads/master ];
then
echo "Manual pushing to this repo is restricted"
exit 1
fi
fi
Disable push to specific branches on GitHub
Ok I got the answer from IRC after a long chat. I'll have to work with forks and pull requests, or add pre-push hooks on each dev's machine since GitHub doesn't allow per branch permissions neither pre-publish canceling hooks. Here is a part of the answers I got:
Fork the repository. then the developer can work on their own version of the repository, and doesn't have to worry about committing to the wrong branch. And then someone upstream can always merge into whatever branch should be committed into.
Yeah but we're a company and we don't want that all our devs have forks
Why not?
Well they should be able to push their branch on a common repo to work with some other devs on the same feature for example.
Have a read through https://help.github.com/articles/using-pull-requests. You can still send patches around between multiple forks. This is the model that git was built on
I know but I want to be able to see quickly in a central way the actual work on any feature/hotfix, ...
To cut a long story short: GitHub doesn't support per-branch permissions
Prohibit remote pushing to the master branch in git
You should take a look at the sample update
hook called update-paranoid
in the contrib
directory of the git distribution. It allows you to set up per-branch ACLs restricting who is allowed to push to which branches. This way you can restrict updating master to just release owners.
I'm not quite sure what you mean by "only updated via branch merging". I'm assuming that your central repository is bare, in which case branches are usually only updated by a push. There's no conceptual difference in git between pushing a commit that is a merge and one that isn't so I'm not sure what your criteria for restricting the type of update for master is intended to be.
In the case that you are pushing to a non-bare central repository and master
is always the checked out branch then you can simply set the config variable receive.denyCurrentBranch
to true
or refuse
.
Related Topics
Read Serial Data Without High CPU Use
Linux Service Can't Load Library Path in The /Etc/Ld.So.Conf.D
Adjust Audio Volume Level with Cli Omxplayer - Raspberry Pi
Why Processes Are Deprived of CPU for Too Long While Busy Looping in Linux Kernel
How to Send Esc/Pos Commands to Thermal Printer in Linux
Can 'Find' or Any Other Tool Search for Files Breadth-First
Extract Lines When Column K Is Empty with Awk/Perl
Correcting The Gcc Command Line Ordering Using Automake
Linux: How to Lock The Pages of a Process in Memory
Detecting The Output Stream Type of a Shell Script
Is There Any Difference Between Executable Binary Files Between Distributions
Writing a Syscall to Count Context Switches of a Process
Scsi Read (10) and Write (10) with The Scsi Generic Interface
Short Command to Find Total Size of Files Matching a Wild Card