This is my first time setting up a git server, so I don't really know what I am doing yet. Anyways, I have a git server setup with a user, What I want is to have multiple developers that can create their own branches and push the branches to origin, but I don't want them to push anything to master; an admin will merge after a code review. Is that possible?
3 Answers
Gitolite can do this for you. There's no way for you to set this up with the default git setup.
If you don't want to use Gitolite, add this to your update
hook:
[ "$1" != refs/heads/master ] || {
echo "ERROR: you are not allowed to update master" >&2
exit 1
}
-
Won't this only allow pushing to master, not the other way around? May 29, 2015 at 12:51
-
1@daramarak: No, notice the
||
. It's expressed as an assertion: "the ref is not master, or else error out." I did it that way instead of[ "$1" = refs/heads/master ] && { ... }
because assertion style is idiomatic for shell scripting (it makes error handling easier). May 29, 2015 at 18:08 -
Ah, I see. Not to used to read bash scripting. A bit confusing. Was comparing this to an another answer. Anyway this should have been the correct answer. Thanks. May 30, 2015 at 5:11
Extending the answer of Richard a bit: Use the following snippet as your "hooks/update" and pushing to master will only be allowed to the user with the name "git-repo-admin":
#!/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
-
This won't work where my origin is set to [email protected]:/git/main.git, as $USER will always be "git".– RCrossOct 15, 2014 at 15:57
-
USER_EMAIL=$(git log -1 --format=format:%ae HEAD) USER_NAME=$(git log -1 --format=format:%an HEAD) answers.atlassian.com/questions/58346/…– KrekkonNov 25, 2014 at 11:45