Like other version control system git also provide hook facilities to perform customized task.hooks are basically scripts which can be written in shell, perl, python, ruby etc.
In order to restrict git push to master(or other specific branch), changes should go in repo.git/hooks/update.
1.Copy update.sample script in hooks directory to update.
cp repo.git/hooks/update.sample repo.git/hooks/update
2.Empty the newly copied update file
> repo.git/hooks/update
Skip the above two steps if you are already using update hook for other purposes.
3.Copy the below script and paste in update file
#!/bin/bashif test $USER == "git-admin"; then
echo "--------------PERMITTING PUSH FOR GIT ADMIN--------------"
else[ "$1" != refs/heads/master ] || {
echo "--------------ERROR: $USER is NOT ALLOWED TO UPDATE MASTER--------------" >&2
exit 1
}
fi
git push should be now restricted to "git-admin" user. Others will not be able to push to master branch.